-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from savindi7/feat-text-field
feat(react): add `TextField` components
- Loading branch information
Showing
42 changed files
with
1,332 additions
and
30 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/react/src/components/FormControl/FormControl.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs'; | ||
import dedent from 'ts-dedent'; | ||
import StoryConfig from '../../../.storybook/story-config.ts'; | ||
import FormControl from './FormControl.tsx'; | ||
import InputLabel from '../InputLabel'; | ||
import Input from '../Input'; | ||
|
||
export const meta = { | ||
component: FormControl, | ||
title: StoryConfig.FormControl.hierarchy, | ||
}; | ||
|
||
<Meta title={meta.title} component={meta.component} /> | ||
|
||
export const Template = args => { | ||
return ( | ||
<FormControl {...args}> | ||
<InputLabel htmlFor="component-simple1">Form Input Label</InputLabel> | ||
<Input id="component-simple1" defaultValue="TextField1" /> | ||
<Input id="component-simple1" defaultValue="TextField2" /> | ||
</FormControl> | ||
) | ||
} | ||
|
||
# Form Control | ||
|
||
- [Overview](#overview) | ||
- [Props](#props) | ||
- [Usage](#usage) | ||
- [Variants](#variants) | ||
|
||
## Overview | ||
|
||
Used to apply a common state to form inputs; `FormLabel`, `FormHelperText`, `Input`, `InputLabel`. | ||
|
||
<Canvas> | ||
<Story name="Overview" args={{margin: 'normal'}}> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
## Props | ||
|
||
<ArgsTable story="Overview" /> | ||
|
||
## Usage | ||
|
||
Import and use the `FormControl` component in your components as follows. | ||
|
||
<Source | ||
language="jsx" | ||
dark | ||
format | ||
code={dedent`import FormControl from '@oxygen-ui/react/FormControl';\n`} | ||
/> | ||
|
||
## Variants | ||
|
||
### Color | ||
|
||
#### Primary | ||
|
||
<Canvas> | ||
<Story name="Primary" args={{color: 'primary', margin: 'normal'}} > | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
#### Secondary | ||
|
||
<Canvas> | ||
<Story name="Secondary" args={{color: 'secondary', margin: 'normal'}} > | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
### Error | ||
|
||
<Canvas> | ||
<Story name="Error" args={{error: true, margin: 'normal'}} > | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
### Focused | ||
|
||
<Canvas> | ||
<Story name="Focused" args={{focused: true, margin: 'normal'}} > | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
### Disabled | ||
|
||
<Canvas> | ||
<Story name="Disabled" args={{disabled: true, margin: 'normal'}} > | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import MuiFormControl, {FormControlProps as MuiFormControlProps} from '@mui/material/FormControl'; | ||
import clsx from 'clsx'; | ||
import {ElementType, FC, ReactElement} from 'react'; | ||
import {WithWrapperProps} from '../../models'; | ||
import {composeComponentDisplayName} from '../../utils'; | ||
import './form-control.scss'; | ||
|
||
export type FormControlProps<C extends ElementType = ElementType> = { | ||
component?: C; | ||
} & Omit<MuiFormControlProps<C>, 'component'>; | ||
|
||
const COMPONENT_NAME: string = 'FormControl'; | ||
|
||
const FormControl: FC<FormControlProps> & WithWrapperProps = <C extends ElementType>( | ||
props: FormControlProps<C>, | ||
): ReactElement => { | ||
const {className, ...rest} = props; | ||
|
||
const classes: string = clsx('oxygen-form-control', className); | ||
|
||
return <MuiFormControl className={classes} {...rest} />; | ||
}; | ||
|
||
FormControl.displayName = composeComponentDisplayName(COMPONENT_NAME); | ||
FormControl.muiName = COMPONENT_NAME; | ||
FormControl.defaultProps = {}; | ||
|
||
export default FormControl; |
32 changes: 32 additions & 0 deletions
32
packages/react/src/components/FormControl/__test__/FormControl.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import {render} from '@unit-testing'; | ||
import FormControl from '../FormControl'; | ||
|
||
describe('FormControl', () => { | ||
it('should render successfully', () => { | ||
const {baseElement} = render(<FormControl />); | ||
expect(baseElement).toBeTruthy(); | ||
}); | ||
|
||
it('should match the snapshot', () => { | ||
const {baseElement} = render(<FormControl />); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/react/src/components/FormControl/__test__/__snapshots__/FormControl.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FormControl should match the snapshot 1`] = ` | ||
<body> | ||
<div> | ||
<div | ||
class="MuiFormControl-root oxygen-form-control css-1nrlq1o-MuiFormControl-root" | ||
/> | ||
</div> | ||
</body> | ||
`; |
21 changes: 21 additions & 0 deletions
21
packages/react/src/components/FormControl/form-control.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
.oxygen-form-control { | ||
/* Add Styles */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export {default} from './FormControl'; | ||
export type {FormControlProps} from './FormControl'; |
Oops, something went wrong.