-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Initial implementation of Field and InputField #24394
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06d1725
Initial implementation of Field and InputField
behowell 84ff5e9
Revert some dependencies in react-field for now
behowell edf391a
Merge branch 'master' of https://github.com/microsoft/fluentui into f…
behowell 4189e9a
Rename fieldOrientation to orientation, and add UseFieldParams argume…
behowell 4dba2ae
Rename helperText to hint
behowell 7040897
Rename status to validationState, statusText to validationMessage, an…
behowell 049a28f
Merge branch 'field/implement' of https://github.com/behowell/fluentu…
behowell 0e4340f
Rename `fieldComponent` slot to `field`
behowell 6d47406
Rename `field` slot to `control`
behowell 11aa35b
Merge branch 'master' of https://github.com/microsoft/fluentui into f…
behowell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
| export * from './components/InputField/index'; |
18 changes: 0 additions & 18 deletions
18
packages/react-components/react-field/src/components/Field/Field.test.tsx
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
packages/react-components/react-field/src/components/Field/Field.tsx
This file was deleted.
Oops, something went wrong.
98 changes: 91 additions & 7 deletions
98
packages/react-components/react-field/src/components/Field/Field.types.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,17 +1,101 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import * as React from 'react'; | ||
| import { Label } from '@fluentui/react-label'; | ||
| import type { ComponentProps, ComponentState, Slot, SlotClassNames } from '@fluentui/react-utilities'; | ||
| import type { SlotComponent } from './SlotComponent.types'; | ||
|
|
||
| export type FieldSlots = { | ||
| root: Slot<'div'>; | ||
| /** | ||
| * The minimum requirement for a component used by Field. | ||
| * | ||
| * Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop, | ||
| * but it is still allowed to have a children prop. | ||
| */ | ||
| export type FieldComponent = React.VoidFunctionComponent< | ||
| Pick< | ||
| React.HTMLAttributes<HTMLElement>, | ||
| 'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-errormessage' | ||
| > | ||
| >; | ||
|
|
||
| /** | ||
| * Slots added by Field | ||
| */ | ||
| export type FieldSlots<T extends FieldComponent> = { | ||
| root: NonNullable<Slot<'div'>>; | ||
|
|
||
| /** | ||
| * The underlying component wrapped by this field. | ||
| * | ||
| * This is the PRIMARY slot: all intrinsic HTML properties will be applied to this slot, | ||
| * except `className` and `style`, which remain on the root slot. | ||
| */ | ||
| field: SlotComponent<T>; | ||
|
|
||
| /** | ||
| * The label associated with the field. | ||
| */ | ||
| label?: Slot<typeof Label>; | ||
|
|
||
| /** | ||
| * A message about the validation state. The appearance of the `validationMessage` depends on `validationState`. | ||
| */ | ||
| validationMessage?: Slot<'span'>; | ||
|
|
||
| /** | ||
| * The icon associated with the `validationMessage`. If the `validationState` prop is set, this will default to an | ||
| * icon corresponding to that state. | ||
| * | ||
| * This will only be displayed if `validationMessage` is set. | ||
| */ | ||
| validationMessageIcon?: Slot<'span'>; | ||
|
|
||
| /** | ||
| * Additional hint text below the field. | ||
| */ | ||
| hint?: Slot<'span'>; | ||
| }; | ||
|
|
||
| /** | ||
| * Field Props | ||
| */ | ||
| export type FieldProps = ComponentProps<FieldSlots> & {}; | ||
| export type FieldProps<T extends FieldComponent> = ComponentProps<Partial<FieldSlots<T>>, 'field'> & { | ||
| /** | ||
| * The orientation of the label relative to the field component. | ||
| * This only affects the label, and not the validationMessage or hint (which always appear below the field component). | ||
| * | ||
| * @default vertical | ||
| */ | ||
| orientation?: 'vertical' | 'horizontal'; | ||
|
|
||
| /** | ||
| * The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some | ||
| * field components, an `validationState="error"` causes the border to become red. | ||
| * | ||
| * @default undefined | ||
| */ | ||
| validationState?: 'error' | 'warning' | 'success'; | ||
| }; | ||
|
|
||
| /** | ||
| * Props that are supported by Field, but not required to be supported by the component that implements field. | ||
| */ | ||
| export type OptionalFieldComponentProps = { | ||
| /** | ||
| * Whether the field label should be marked as required. | ||
| */ | ||
| required?: boolean; | ||
|
|
||
| /** | ||
| * Size of the field label. | ||
| * | ||
| * Number sizes will be ignored, but are allowed because the HTML `<input>` element has a prop `size?: number`. | ||
| */ | ||
| size?: 'small' | 'medium' | 'large' | number; | ||
spmonahan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| /** | ||
| * State used in rendering Field | ||
| */ | ||
| export type FieldState = ComponentState<FieldSlots>; | ||
| // TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from FieldProps. | ||
| // & Required<Pick<FieldProps, 'propName'>> | ||
| export type FieldState<T extends FieldComponent> = ComponentState<Required<FieldSlots<T>>> & | ||
| Pick<FieldProps<T>, 'orientation' | 'validationState'> & { | ||
| classNames: SlotClassNames<FieldSlots<T>>; | ||
| }; | ||
25 changes: 25 additions & 0 deletions
25
packages/react-components/react-field/src/components/Field/SlotComponent.types.ts
This file contains hidden or 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,25 @@ | ||
| import * as React from 'react'; | ||
| import type { SlotShorthandValue, SlotRenderFunction } from '@fluentui/react-utilities'; | ||
|
|
||
| // | ||
| // TEMPORARY definition of the SlotComponent type, until it is available from react-utilities | ||
| // | ||
|
|
||
| export type SlotComponent<Type extends React.ComponentType | React.VoidFunctionComponent> = WithSlotShorthandValue< | ||
| Type extends React.ComponentType<infer Props> | ||
| ? // If this is a VoidFunctionComponent that doesn't allow children, add { children?: never } | ||
| WithSlotRenderFunction<Props extends { children?: unknown } ? Props : Props & { children?: never }> | ||
| : never | ||
| >; | ||
|
|
||
| // | ||
| // TEMPORARY copied versions of the non-exported helper types from react-utilities | ||
| // | ||
|
|
||
| type WithSlotShorthandValue<Props extends { children?: unknown }> = | ||
| | Props | ||
| | Extract<SlotShorthandValue, Props['children']>; | ||
|
|
||
| type WithSlotRenderFunction<Props extends { children?: unknown }> = Props & { | ||
| children?: Props['children'] | SlotRenderFunction<Props>; | ||
| }; |
11 changes: 0 additions & 11 deletions
11
packages/react-components/react-field/src/components/Field/__snapshots__/Field.test.tsx.snap
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/react-components/react-field/src/components/Field/index.ts
This file contains hidden or 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
22 changes: 17 additions & 5 deletions
22
packages/react-components/react-field/src/components/Field/renderField.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,13 +1,25 @@ | ||
| import * as React from 'react'; | ||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { FieldState, FieldSlots } from './Field.types'; | ||
| import type { FieldComponent, FieldSlots, FieldState } from './Field.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of Field | ||
| */ | ||
| export const renderField_unstable = (state: FieldState) => { | ||
| const { slots, slotProps } = getSlots<FieldSlots>(state); | ||
| export const renderField_unstable = <T extends FieldComponent>(state: FieldState<T>) => { | ||
| const { slots, slotProps } = getSlots<FieldSlots<FieldComponent>>(state as FieldState<FieldComponent>); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <slots.root {...slotProps.root} />; | ||
| return ( | ||
| <slots.root {...slotProps.root}> | ||
| {slots.label && <slots.label {...slotProps.label} />} | ||
| {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */} | ||
| {slots.field && <slots.field {...(slotProps.field as any)} />} | ||
| {slots.validationMessage && ( | ||
| <slots.validationMessage {...slotProps.validationMessage}> | ||
| {slots.validationMessageIcon && <slots.validationMessageIcon {...slotProps.validationMessageIcon} />} | ||
| {slotProps.validationMessage.children} | ||
| </slots.validationMessage> | ||
| )} | ||
| {slots.hint && <slots.hint {...slotProps.hint} />} | ||
| </slots.root> | ||
| ); | ||
| }; |
28 changes: 0 additions & 28 deletions
28
packages/react-components/react-field/src/components/Field/useField.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.