-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Added BreadcrumbItem and BreadcrumbDivider components #26693
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
ValentinaKozlova
merged 6 commits into
microsoft:master
from
ValentinaKozlova:feat/breadcrumb-component-structure
Mar 10, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
07d7092
Added BreadcrumbItem and BreadcrumbDivider
ValentinaKozlova 2d377b7
Added basic structure of the component
ValentinaKozlova 5fb9a51
PR fix
ValentinaKozlova ff560f5
Updated react-breadcrumb.api.md
ValentinaKozlova f42d606
Merge branch 'master' into feat/breadcrumb-component-structure
ValentinaKozlova 602cfe7
Updated deps
ValentinaKozlova 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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-breadcrumb/src/BreadcrumbDivider.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 @@ | ||
| export * from './components/BreadcrumbDivider/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-breadcrumb/src/BreadcrumbItem.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 @@ | ||
| export * from './components/BreadcrumbItem/index'; |
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
3 changes: 2 additions & 1 deletion
3
packages/react-components/react-breadcrumb/src/components/Breadcrumb/Breadcrumb.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
11 changes: 0 additions & 11 deletions
11
...ponents/react-breadcrumb/src/components/Breadcrumb/__snapshots__/Breadcrumb.test.tsx.snap
This file was deleted.
Oops, something went wrong.
6 changes: 2 additions & 4 deletions
6
packages/react-components/react-breadcrumb/src/components/Breadcrumb/renderBreadcrumb.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,11 @@ | ||
| import * as React from 'react'; | ||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { BreadcrumbState, BreadcrumbSlots } from './Breadcrumb.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of Breadcrumb | ||
| */ | ||
| export const renderBreadcrumb_unstable = (state: BreadcrumbState) => { | ||
| const { slots, slotProps } = getSlots<BreadcrumbSlots>(state); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <slots.root {...slotProps.root} />; | ||
| const { root, list } = slotProps; | ||
| return <slots.root {...root}>{slots.list && <slots.list {...list}>{root.children}</slots.list>}</slots.root>; | ||
| }; |
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
26 changes: 26 additions & 0 deletions
26
...t-components/react-breadcrumb/src/components/BreadcrumbDivider/BreadcrumbDivider.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,26 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { BreadcrumbDivider } from './BreadcrumbDivider'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
|
|
||
| describe('BreadcrumbDivider', () => { | ||
| isConformant({ | ||
| Component: BreadcrumbDivider, | ||
| displayName: 'BreadcrumbDivider', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<BreadcrumbDivider>Default BreadcrumbDivider</BreadcrumbDivider>); | ||
| expect(result.container).toMatchInlineSnapshot(` | ||
| <div> | ||
| <span | ||
| class="fui-BreadcrumbDivider" | ||
| > | ||
| > | ||
| </span> | ||
| </div> | ||
| `); | ||
| }); | ||
| }); |
23 changes: 23 additions & 0 deletions
23
.../react-components/react-breadcrumb/src/components/BreadcrumbDivider/BreadcrumbDivider.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,23 @@ | ||
| import * as React from 'react'; | ||
| import { useBreadcrumbDivider_unstable } from './useBreadcrumbDivider'; | ||
| import { renderBreadcrumbDivider_unstable } from './renderBreadcrumbDivider'; | ||
| import { useBreadcrumbDividerStyles_unstable } from './useBreadcrumbDividerStyles'; | ||
| import type { BreadcrumbDividerProps } from './BreadcrumbDivider.types'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts'; | ||
|
|
||
| /** | ||
| * BreadcrumbDivider component - TODO: add more docs | ||
| */ | ||
| export const BreadcrumbDivider: ForwardRefComponent<BreadcrumbDividerProps> = React.forwardRef((props, ref) => { | ||
| const state = useBreadcrumbDivider_unstable(props, ref); | ||
|
|
||
| useBreadcrumbDividerStyles_unstable(state); | ||
|
|
||
| const { useTextStyles_unstable: useCustomStyles } = useCustomStyleHooks_unstable(); | ||
| useCustomStyles(state); | ||
|
|
||
| return renderBreadcrumbDivider_unstable(state); | ||
| }); | ||
|
|
||
| BreadcrumbDivider.displayName = 'BreadcrumbDivider'; | ||
18 changes: 18 additions & 0 deletions
18
...t-components/react-breadcrumb/src/components/BreadcrumbDivider/BreadcrumbDivider.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,18 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
|
||
| export type BreadcrumbDividerSlots = { | ||
| root: Slot<'span'>; | ||
| }; | ||
|
|
||
| /** | ||
| * BreadcrumbDivider Props | ||
| */ | ||
| export type BreadcrumbDividerProps = ComponentProps<BreadcrumbDividerSlots> & {}; | ||
|
|
||
| /** | ||
| * State used in rendering BreadcrumbDivider | ||
| */ | ||
| export type BreadcrumbDividerState = ComponentState<BreadcrumbDividerSlots>; | ||
| // TODO: Remove semicolon from previous line, uncomment next line, | ||
| //and provide union of props to pick from BreadcrumbDividerProps. | ||
| // & Required<Pick<BreadcrumbDividerProps, 'propName'>> |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-breadcrumb/src/components/BreadcrumbDivider/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 './BreadcrumbDivider'; | ||
| export * from './BreadcrumbDivider.types'; | ||
| export * from './renderBreadcrumbDivider'; | ||
| export * from './useBreadcrumbDivider'; | ||
| export * from './useBreadcrumbDividerStyles'; |
13 changes: 13 additions & 0 deletions
13
...-components/react-breadcrumb/src/components/BreadcrumbDivider/renderBreadcrumbDivider.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,13 @@ | ||
| import * as React from 'react'; | ||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { BreadcrumbDividerState, BreadcrumbDividerSlots } from './BreadcrumbDivider.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of BreadcrumbDivider | ||
| */ | ||
| export const renderBreadcrumbDivider_unstable = (state: BreadcrumbDividerState) => { | ||
| const { slots, slotProps } = getSlots<BreadcrumbDividerSlots>(state); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <slots.root {...slotProps.root}>></slots.root>; | ||
| }; |
31 changes: 31 additions & 0 deletions
31
...eact-components/react-breadcrumb/src/components/BreadcrumbDivider/useBreadcrumbDivider.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,31 @@ | ||
| import * as React from 'react'; | ||
| import { getNativeElementProps } from '@fluentui/react-utilities'; | ||
| import type { BreadcrumbDividerProps, BreadcrumbDividerState } from './BreadcrumbDivider.types'; | ||
|
|
||
| /** | ||
| * Create the state required to render BreadcrumbDivider. | ||
| * | ||
| * The returned state can be modified with hooks such as useBreadcrumbDividerStyles_unstable, | ||
| * before being passed to renderBreadcrumbDivider_unstable. | ||
| * | ||
| * @param props - props from this instance of BreadcrumbDivider | ||
| * @param ref - reference to root HTMLElement of BreadcrumbDivider | ||
| */ | ||
| export const useBreadcrumbDivider_unstable = ( | ||
| props: BreadcrumbDividerProps, | ||
| ref: React.Ref<HTMLElement>, | ||
| ): BreadcrumbDividerState => { | ||
| return { | ||
| // TODO add appropriate props/defaults | ||
| components: { | ||
| // TODO add each slot's element type or component | ||
| root: 'span', | ||
| }, | ||
| // TODO add appropriate slots, for example: | ||
| // mySlot: resolveShorthand(props.mySlot), | ||
| root: getNativeElementProps('div', { | ||
| ref, | ||
| ...props, | ||
| }), | ||
| }; | ||
| }; |
33 changes: 33 additions & 0 deletions
33
...omponents/react-breadcrumb/src/components/BreadcrumbDivider/useBreadcrumbDividerStyles.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,33 @@ | ||
| import { makeStyles, mergeClasses } from '@griffel/react'; | ||
| import type { BreadcrumbDividerSlots, BreadcrumbDividerState } from './BreadcrumbDivider.types'; | ||
| import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
|
||
| export const breadcrumbDividerClassNames: SlotClassNames<BreadcrumbDividerSlots> = { | ||
| root: 'fui-BreadcrumbDivider', | ||
| // TODO: add class names for all slots on BreadcrumbDividerSlots. | ||
| // Should be of the form `<slotName>: 'fui-BreadcrumbDivider__<slotName>` | ||
| }; | ||
|
|
||
| /** | ||
| * Styles for the root slot | ||
| */ | ||
| const useStyles = makeStyles({ | ||
| root: { | ||
| // TODO Add default styles for the root element | ||
| }, | ||
|
|
||
| // TODO add additional classes for different states and/or slots | ||
| }); | ||
|
|
||
| /** | ||
| * Apply styling to the BreadcrumbDivider slots based on the state | ||
| */ | ||
| export const useBreadcrumbDividerStyles_unstable = (state: BreadcrumbDividerState): BreadcrumbDividerState => { | ||
| const styles = useStyles(); | ||
| state.root.className = mergeClasses(breadcrumbDividerClassNames.root, styles.root, state.root.className); | ||
|
|
||
| // TODO Add class names to slots, for example: | ||
| // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className); | ||
|
|
||
| return state; | ||
| }; |
31 changes: 31 additions & 0 deletions
31
...s/react-components/react-breadcrumb/src/components/BreadcrumbItem/BreadcrumbItem.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,31 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { BreadcrumbItem } from './BreadcrumbItem'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
|
|
||
| describe('BreadcrumbItem', () => { | ||
| isConformant({ | ||
| Component: BreadcrumbItem, | ||
| displayName: 'BreadcrumbItem', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<BreadcrumbItem>Default BreadcrumbItem</BreadcrumbItem>); | ||
| expect(result.container).toMatchInlineSnapshot(` | ||
| <div> | ||
| <div | ||
| class="fui-BreadcrumbItem" | ||
| > | ||
| Default BreadcrumbItem | ||
| <span | ||
| class="fui-BreadcrumbDivider fui-BreadcrumbItem__divider" | ||
| > | ||
| > | ||
| </span> | ||
| </div> | ||
| </div> | ||
| `); | ||
| }); | ||
| }); |
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.