-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add all Field components to react-field #24426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 25 commits
06d1725
84ff5e9
edf391a
4189e9a
4dba2ae
7040897
6ee6dcd
efbec05
049a28f
3235bc2
d77c166
988ae99
0e4340f
6d47406
11aa35b
5cba764
79ba601
364f387
94a9bba
7fe46a7
c3df78f
249713e
4967264
9816cd4
bcdfd1f
47c41fc
5d77563
6d1fe7f
516c8b2
a5d5b04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/CheckboxField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/ComboboxField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/RadioGroupField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/SelectField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/SliderField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/SpinButtonField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/SwitchField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/TextareaField/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import * as React from 'react'; | ||
| import { resetIdsForTests } from '@fluentui/react-utilities'; | ||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../common/isConformant'; | ||
| import { CheckboxField, checkboxFieldClassNames } from './CheckboxField'; | ||
|
|
||
| describe('CheckboxField', () => { | ||
| isConformant({ | ||
| Component: CheckboxField, | ||
| displayName: 'CheckboxField', | ||
| primarySlot: 'control', | ||
| testOptions: { | ||
| 'has-static-classnames': [ | ||
| { | ||
| props: { | ||
| label: 'label', | ||
| fieldLabel: 'fieldLabel', | ||
| validationState: 'error', | ||
| validationMessage: 'validationMessage', | ||
| hint: 'hint', | ||
| }, | ||
| expectedClassNames: checkboxFieldClassNames, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| beforeEach(resetIdsForTests); | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<CheckboxField label="Checkbox" />); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import * as React from 'react'; | ||
| import type { CheckboxProps } from '@fluentui/react-checkbox'; | ||
| import { Checkbox } from '@fluentui/react-checkbox'; | ||
| import { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import type { FieldProps } from '../../Field'; | ||
| import { getFieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from '../../Field'; | ||
|
|
||
| export type CheckboxFieldProps = Omit<FieldProps<typeof Checkbox>, 'label'> & { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm talking to Design about how the label prop of Switch should work. I logged this issue to implement the final behavior once we decide how it should work: |
||
| /** | ||
| * The Checkbox's label. | ||
| */ | ||
| label?: CheckboxProps['label']; | ||
|
|
||
| /** | ||
| * The label for the CheckboxField, which appears above or before the Checkbox, depending on the `orientation` prop. | ||
| * It is recommended to only set the `label` prop, and not `fieldLabel`. | ||
| */ | ||
| fieldLabel?: FieldProps<typeof Checkbox>['label']; | ||
| }; | ||
|
|
||
| export const checkboxFieldClassNames = getFieldClassNames('CheckboxField'); | ||
|
|
||
| export const CheckboxField: ForwardRefComponent<CheckboxFieldProps> = React.forwardRef((props, ref) => { | ||
| const { fieldLabel, required, label, control, ...restOfProps } = props; | ||
|
|
||
| const state = useField_unstable({ | ||
| props: { | ||
| // Use the fieldLabel prop as the Field's label | ||
| label: fieldLabel, | ||
| // Use the label prop as the Checkbox's label | ||
| control: { label, required, ...control }, | ||
| ...restOfProps, | ||
| }, | ||
| ref, | ||
| component: Checkbox, | ||
| classNames: checkboxFieldClassNames, | ||
| }); | ||
| useFieldStyles_unstable(state); | ||
| return renderField_unstable(state); | ||
| }); | ||
|
|
||
| CheckboxField.displayName = 'CheckboxField'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`CheckboxField renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-CheckboxField" | ||
| > | ||
| <span | ||
| class="fui-Checkbox fui-CheckboxField__control" | ||
| > | ||
| <input | ||
| class="fui-Checkbox__input" | ||
| type="checkbox" | ||
| /> | ||
| <div | ||
| aria-hidden="true" | ||
| class="fui-Checkbox__indicator" | ||
| > | ||
| <svg | ||
| aria-hidden="true" | ||
| class="" | ||
| fill="currentColor" | ||
| height="12" | ||
| viewBox="0 0 12 12" | ||
| width="12" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M9.76 3.2c.3.29.32.76.04 1.06l-4.25 4.5a.75.75 0 01-1.08.02L2.22 6.53a.75.75 0 011.06-1.06l1.7 1.7L8.7 3.24a.75.75 0 011.06-.04z" | ||
| fill="currentColor" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| <label | ||
| class="fui-Label fui-Checkbox__label" | ||
| for="checkbox-2" | ||
| > | ||
| Checkbox | ||
| </label> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './CheckboxField'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import * as React from 'react'; | ||
| import { resetIdsForTests } from '@fluentui/react-utilities'; | ||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../common/isConformant'; | ||
| import { ComboboxField, comboboxFieldClassNames } from './ComboboxField'; | ||
|
|
||
| describe('ComboboxField', () => { | ||
| isConformant({ | ||
| Component: ComboboxField, | ||
| displayName: 'ComboboxField', | ||
| primarySlot: 'control', | ||
| testOptions: { | ||
| 'has-static-classnames': [ | ||
| { | ||
| props: { | ||
| label: 'label', | ||
| validationState: 'error', | ||
| validationMessage: 'validationMessage', | ||
| hint: 'hint', | ||
| }, | ||
| expectedClassNames: comboboxFieldClassNames, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| beforeEach(resetIdsForTests); | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<ComboboxField />); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import * as React from 'react'; | ||
| import { Combobox } from '@fluentui/react-combobox'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import type { FieldProps } from '../../Field'; | ||
| import { getFieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from '../../Field'; | ||
|
|
||
| export type ComboboxFieldProps = FieldProps<typeof Combobox>; | ||
|
|
||
| export const comboboxFieldClassNames = getFieldClassNames('ComboboxField'); | ||
|
|
||
| export const ComboboxField: ForwardRefComponent<ComboboxFieldProps> = React.forwardRef((props, ref) => { | ||
| const state = useField_unstable({ props, ref, component: Combobox, classNames: comboboxFieldClassNames }); | ||
| useFieldStyles_unstable(state); | ||
| return renderField_unstable(state); | ||
| }); | ||
|
|
||
| ComboboxField.displayName = 'ComboboxField'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`ComboboxField renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-ComboboxField" | ||
| > | ||
| <div | ||
| class="fui-Combobox fui-ComboboxField__control" | ||
| > | ||
| <input | ||
| aria-expanded="false" | ||
| class="fui-Combobox__input" | ||
| role="combobox" | ||
| type="text" | ||
| value="" | ||
| /> | ||
| <span | ||
| class="fui-Combobox__expandIcon" | ||
| > | ||
| <svg | ||
| aria-hidden="true" | ||
| class="" | ||
| fill="currentColor" | ||
| height="1em" | ||
| viewBox="0 0 20 20" | ||
| width="1em" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M15.85 7.65c.2.2.2.5 0 .7l-5.46 5.49a.55.55 0 01-.78 0L4.15 8.35a.5.5 0 11.7-.7L10 12.8l5.15-5.16c.2-.2.5-.2.7 0z" | ||
| fill="currentColor" | ||
| /> | ||
| </svg> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './ComboboxField'; |
Uh oh!
There was an error while loading. Please reload this page.