-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Add InfoLabel component #27118
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 all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
35b482b
InfoLabel component boilerplate
behowell 1ac74f2
Initial implementation of InfoLabel
behowell 30b500b
Initial implementation of InfoLabel
behowell bcbbcde
VR tests
behowell b559925
change file
behowell eebf516
Update api.md
behowell 64afdbb
Propagate size to InfoButton
behowell e702572
Add InfoLabel bundle size test
behowell 024e6c3
Add size story
behowell 014a679
Merge branch 'master' of https://github.com/microsoft/fluentui into i…
behowell ab92cf8
Merge branch 'infolabel/create' of https://github.com/behowell/fluent…
behowell e5f80ba
Fix doc link in story
behowell c51ed89
Export InfoLabel from react-components/unstable
behowell 7e00967
Merge branch 'master' of https://github.com/microsoft/fluentui into i…
behowell 31a0200
api.md
behowell 3187869
Update documentation and stories
behowell 8e0a297
Add VR test for no InfoButton
behowell 00c509a
Add tests
behowell f17b83f
Clean up useInfoLabel
behowell dcaf0a6
change file
behowell 54bba7a
Rename content prop to info.
behowell 65a3cbf
Merge branch 'master' of https://github.com/microsoft/fluentui into i…
behowell 35bdcb2
Update dependency version on react-label
behowell dbe07dd
Clean up InfoButtonBestPractices
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
43 changes: 43 additions & 0 deletions
43
apps/vr-tests-react-components/src/stories/InfoLabel.stories.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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { Steps, StoryWright } from 'storywright'; | ||
| import { InfoLabel } from '@fluentui/react-infobutton'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import { TestWrapperDecoratorFixedWidth } from '../utilities/TestWrapperDecorator'; | ||
|
|
||
| storiesOf('InfoLabel', module) | ||
| .addDecorator(TestWrapperDecoratorFixedWidth) | ||
| .addDecorator(story => ( | ||
| <StoryWright steps={new Steps().snapshot('rest', { cropTo: '.testWrapper' }).end()}>{story()}</StoryWright> | ||
| )) | ||
| .addStory('default', () => <InfoLabel info="Test">This is an info label</InfoLabel>, { | ||
| includeHighContrast: true, | ||
| includeDarkMode: true, | ||
| includeRtl: true, | ||
| }) | ||
| .addStory('wrap', () => ( | ||
| <InfoLabel info="Test"> | ||
| This is a very long info label that should wrap to multiple lines and put the info button on the last line | ||
| </InfoLabel> | ||
| )) | ||
| .addStory('size:small', () => ( | ||
| <InfoLabel size="small" info="Test"> | ||
| This is a small info label | ||
| </InfoLabel> | ||
| )) | ||
| .addStory('size:large', () => ( | ||
| <InfoLabel size="large" info="Test"> | ||
| This is a large info label | ||
| </InfoLabel> | ||
| )) | ||
| .addStory( | ||
| 'required', | ||
| () => ( | ||
| <InfoLabel required info="Test"> | ||
| This is a required info label | ||
| </InfoLabel> | ||
| ), | ||
| { | ||
| includeRtl: true, | ||
| }, | ||
| ); | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-components-fff93a07-f531-47a4-ac89-03ebd885c5dc.json
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,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "chore: Export InfoLabel from react-components/unstable", | ||
| "packageName": "@fluentui/react-components", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-infobutton-31dcdbe1-fdb8-4865-b821-6717fd7a1db1.json
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,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "feat: Add InfoLabel component", | ||
| "packageName": "@fluentui/react-infobutton", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
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
7 changes: 7 additions & 0 deletions
7
packages/react-components/react-infobutton/bundle-size/InfoLabel.fixture.js
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,7 @@ | ||
| import { InfoLabel } from '@fluentui/react-infobutton'; | ||
|
|
||
| console.log(InfoLabel); | ||
|
|
||
| export default { | ||
| name: 'InfoLabel', | ||
| }; |
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/InfoLabel/index'; |
46 changes: 46 additions & 0 deletions
46
packages/react-components/react-infobutton/src/components/InfoLabel/InfoLabel.test.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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
| import { InfoLabel } from './InfoLabel'; | ||
|
|
||
| describe('InfoLabel', () => { | ||
| isConformant({ | ||
| Component: InfoLabel, | ||
| displayName: 'InfoLabel', | ||
| primarySlot: 'label', | ||
| testOptions: { | ||
| 'has-static-classnames': [ | ||
| { | ||
| props: { | ||
| info: 'Test', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| it('renders an InfoButton when info is set', () => { | ||
| const result = render(<InfoLabel info="Test">Test label</InfoLabel>); | ||
| expect(result.getByRole('button')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("renders an InfoButton when the infoButton slot's content is set", () => { | ||
| const result = render(<InfoLabel infoButton={{ content: 'Test' }}>Test label</InfoLabel>); | ||
| expect(result.getByRole('button')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('does not render an InfoButton when info is not set', () => { | ||
| const result = render(<InfoLabel>Test label</InfoLabel>); | ||
| expect(result.queryByRole('button')).toBeNull(); | ||
| }); | ||
|
|
||
| it('sets the infoButton aria-labelledby to the label and infoButton', () => { | ||
| const result = render(<InfoLabel info="Test">Test label</InfoLabel>); | ||
|
|
||
| const infoButton = result.getByRole('button'); | ||
| const label = result.getByText('Test label') as HTMLLabelElement; | ||
|
|
||
| expect(infoButton.getAttribute('aria-labelledby')).toBe(`${label.id} ${infoButton.id}`); | ||
| }); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-infobutton/src/components/InfoLabel/InfoLabel.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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import type { InfoLabelProps } from './InfoLabel.types'; | ||
| import { renderInfoLabel_unstable } from './renderInfoLabel'; | ||
| import { useInfoLabel_unstable } from './useInfoLabel'; | ||
| import { useInfoLabelStyles_unstable } from './useInfoLabelStyles'; | ||
|
|
||
| /** | ||
| * InfoLabel component | ||
| */ | ||
| export const InfoLabel: ForwardRefComponent<InfoLabelProps> = React.forwardRef((props, ref) => { | ||
| const state = useInfoLabel_unstable(props, ref); | ||
|
|
||
| useInfoLabelStyles_unstable(state); | ||
| return renderInfoLabel_unstable(state); | ||
| }); | ||
|
|
||
| InfoLabel.displayName = 'InfoLabel'; |
41 changes: 41 additions & 0 deletions
41
packages/react-components/react-infobutton/src/components/InfoLabel/InfoLabel.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,41 @@ | ||
| import { Label } from '@fluentui/react-label'; | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import { InfoButton } from '../InfoButton'; | ||
| import type { InfoButtonProps } from '../InfoButton'; | ||
|
|
||
| export type InfoLabelSlots = { | ||
| root: NonNullable<Slot<'span'>>; | ||
|
|
||
| /** | ||
| * The Label component. | ||
| * | ||
| * It is not typically necessary to use this prop. The label text is the child of the `<InfoLabel>`, and other props | ||
| * such as `size` and `required` should be set directly on the `InfoLabel`. | ||
| * | ||
| * This is the PRIMARY slot: all native properties specified directly on `<InfoLabel>` will be applied to this slot, | ||
| * except `className` and `style`, which remain on the root slot. | ||
| */ | ||
| label: NonNullable<Slot<typeof Label>>; | ||
|
|
||
| /** | ||
| * The InfoButton component. | ||
| * | ||
| * It is not typically necessary to use this prop. The content can be set using the `info` prop of the InfoLabel. | ||
| */ | ||
| infoButton: Slot<typeof InfoButton>; | ||
| }; | ||
|
|
||
| /** | ||
| * InfoLabel Props | ||
| */ | ||
| export type InfoLabelProps = ComponentProps<Partial<InfoLabelSlots>, 'label'> & { | ||
| /** | ||
| * The content of the InfoButton's popover. | ||
| */ | ||
| info?: InfoButtonProps['content']; | ||
| }; | ||
|
|
||
| /** | ||
| * State used in rendering InfoLabel | ||
| */ | ||
| export type InfoLabelState = ComponentState<InfoLabelSlots> & Pick<InfoLabelProps, 'size'>; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-infobutton/src/components/InfoLabel/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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export * from './InfoLabel'; | ||
| export * from './InfoLabel.types'; | ||
| export * from './renderInfoLabel'; | ||
| export * from './useInfoLabel'; | ||
| export * from './useInfoLabelStyles'; |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-infobutton/src/components/InfoLabel/renderInfoLabel.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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { InfoLabelSlots, InfoLabelState } from './InfoLabel.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of InfoLabel | ||
| */ | ||
| export const renderInfoLabel_unstable = (state: InfoLabelState) => { | ||
| const { slots, slotProps } = getSlots<InfoLabelSlots>(state); | ||
|
|
||
| return ( | ||
| <slots.root {...slotProps.root}> | ||
| <slots.label {...slotProps.label} /> | ||
| {slots.infoButton && <slots.infoButton {...slotProps.infoButton} />} | ||
| </slots.root> | ||
| ); | ||
| }; |
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.