-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scaffold react-skeleton components (#26640)
- Loading branch information
Showing
49 changed files
with
694 additions
and
5 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/react-components/react-skeleton/.storybook/main.js
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,14 @@ | ||
const rootMain = require('../../../../.storybook/main'); | ||
|
||
module.exports = /** @type {Omit<import('../../../../.storybook/main'), 'typescript'|'babel'>} */ ({ | ||
...rootMain, | ||
stories: [...rootMain.stories, '../stories/**/*.stories.mdx', '../stories/**/index.stories.@(ts|tsx)'], | ||
addons: [...rootMain.addons], | ||
webpackFinal: (config, options) => { | ||
const localConfig = { ...rootMain.webpackFinal(config, options) }; | ||
|
||
// add your own webpack tweaks if needed | ||
|
||
return localConfig; | ||
}, | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/react-components/react-skeleton/.storybook/preview.js
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,7 @@ | ||
import * as rootPreview from '../../../../.storybook/preview'; | ||
|
||
/** @type {typeof rootPreview.decorators} */ | ||
export const decorators = [...rootPreview.decorators]; | ||
|
||
/** @type {typeof rootPreview.parameters} */ | ||
export const parameters = { ...rootPreview.parameters }; |
10 changes: 10 additions & 0 deletions
10
packages/react-components/react-skeleton/.storybook/tsconfig.json
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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "", | ||
"allowJs": true, | ||
"checkJs": true, | ||
"types": ["static-assets", "environment", "storybook__addons"] | ||
}, | ||
"include": ["../stories/**/*.stories.ts", "../stories/**/*.stories.tsx", "*.js"] | ||
} |
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
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
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 @@ | ||
export * from './components/Skeleton/index'; |
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 @@ | ||
export * from './components/SkeletonCircle/index'; |
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 @@ | ||
export * from './components/SkeletonLine/index'; |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-skeleton/src/components/Skeleton/Skeleton.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,18 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Skeleton } from './Skeleton'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
|
||
describe('Skeleton', () => { | ||
isConformant({ | ||
Component: Skeleton, | ||
displayName: 'Skeleton', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<Skeleton>Default Skeleton</Skeleton>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-skeleton/src/components/Skeleton/Skeleton.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,18 @@ | ||
import * as React from 'react'; | ||
import { useSkeleton_unstable } from './useSkeleton'; | ||
import { renderSkeleton_unstable } from './renderSkeleton'; | ||
import { useSkeletonStyles_unstable } from './useSkeletonStyles'; | ||
import type { SkeletonProps } from './Skeleton.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* Skeleton component - TODO: add more docs | ||
*/ | ||
export const Skeleton: ForwardRefComponent<SkeletonProps> = React.forwardRef((props, ref) => { | ||
const state = useSkeleton_unstable(props, ref); | ||
|
||
useSkeletonStyles_unstable(state); | ||
return renderSkeleton_unstable(state); | ||
}); | ||
|
||
Skeleton.displayName = 'Skeleton'; |
17 changes: 17 additions & 0 deletions
17
packages/react-components/react-skeleton/src/components/Skeleton/Skeleton.types.ts
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,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type SkeletonSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* Skeleton Props | ||
*/ | ||
export type SkeletonProps = ComponentProps<SkeletonSlots> & {}; | ||
|
||
/** | ||
* State used in rendering Skeleton | ||
*/ | ||
export type SkeletonState = ComponentState<SkeletonSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from SkeletonProps. | ||
// & Required<Pick<SkeletonProps, 'propName'>> |
11 changes: 11 additions & 0 deletions
11
...ct-components/react-skeleton/src/components/Skeleton/__snapshots__/Skeleton.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[`Skeleton renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-Skeleton" | ||
> | ||
Default Skeleton | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-skeleton/src/components/Skeleton/index.ts
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,5 @@ | ||
export * from './Skeleton'; | ||
export * from './Skeleton.types'; | ||
export * from './renderSkeleton'; | ||
export * from './useSkeleton'; | ||
export * from './useSkeletonStyles'; |
13 changes: 13 additions & 0 deletions
13
packages/react-components/react-skeleton/src/components/Skeleton/renderSkeleton.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,13 @@ | ||
import * as React from 'react'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import type { SkeletonState, SkeletonSlots } from './Skeleton.types'; | ||
|
||
/** | ||
* Render the final JSX of Skeleton | ||
*/ | ||
export const renderSkeleton_unstable = (state: SkeletonState) => { | ||
const { slots, slotProps } = getSlots<SkeletonSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <slots.root {...slotProps.root} />; | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/react-components/react-skeleton/src/components/Skeleton/useSkeleton.ts
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,28 @@ | ||
import * as React from 'react'; | ||
import { getNativeElementProps } from '@fluentui/react-utilities'; | ||
import type { SkeletonProps, SkeletonState } from './Skeleton.types'; | ||
|
||
/** | ||
* Create the state required to render Skeleton. | ||
* | ||
* The returned state can be modified with hooks such as useSkeletonStyles_unstable, | ||
* before being passed to renderSkeleton_unstable. | ||
* | ||
* @param props - props from this instance of Skeleton | ||
* @param ref - reference to root HTMLElement of Skeleton | ||
*/ | ||
export const useSkeleton_unstable = (props: SkeletonProps, ref: React.Ref<HTMLElement>): SkeletonState => { | ||
return { | ||
// TODO add appropriate props/defaults | ||
components: { | ||
// TODO add each slot's element type or component | ||
root: 'div', | ||
}, | ||
// TODO add appropriate slots, for example: | ||
// mySlot: resolveShorthand(props.mySlot), | ||
root: getNativeElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/react-components/react-skeleton/src/components/Skeleton/useSkeletonStyles.ts
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,33 @@ | ||
import { makeStyles, mergeClasses } from '@griffel/react'; | ||
import type { SkeletonSlots, SkeletonState } from './Skeleton.types'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
||
export const skeletonClassNames: SlotClassNames<SkeletonSlots> = { | ||
root: 'fui-Skeleton', | ||
// TODO: add class names for all slots on SkeletonSlots. | ||
// Should be of the form `<slotName>: 'fui-Skeleton__<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 Skeleton slots based on the state | ||
*/ | ||
export const useSkeletonStyles_unstable = (state: SkeletonState): SkeletonState => { | ||
const styles = useStyles(); | ||
state.root.className = mergeClasses(skeletonClassNames.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; | ||
}; |
18 changes: 18 additions & 0 deletions
18
...ges/react-components/react-skeleton/src/components/SkeletonCircle/SkeletonCircle.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,18 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { SkeletonCircle } from './SkeletonCircle'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
|
||
describe('SkeletonCircle', () => { | ||
isConformant({ | ||
Component: SkeletonCircle, | ||
displayName: 'SkeletonCircle', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<SkeletonCircle>Default SkeletonCircle</SkeletonCircle>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-skeleton/src/components/SkeletonCircle/SkeletonCircle.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,18 @@ | ||
import * as React from 'react'; | ||
import { useSkeletonCircle_unstable } from './useSkeletonCircle'; | ||
import { renderSkeletonCircle_unstable } from './renderSkeletonCircle'; | ||
import { useSkeletonCircleStyles_unstable } from './useSkeletonCircleStyles'; | ||
import type { SkeletonCircleProps } from './SkeletonCircle.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* SkeletonCircle component - TODO: add more docs | ||
*/ | ||
export const SkeletonCircle: ForwardRefComponent<SkeletonCircleProps> = React.forwardRef((props, ref) => { | ||
const state = useSkeletonCircle_unstable(props, ref); | ||
|
||
useSkeletonCircleStyles_unstable(state); | ||
return renderSkeletonCircle_unstable(state); | ||
}); | ||
|
||
SkeletonCircle.displayName = 'SkeletonCircle'; |
17 changes: 17 additions & 0 deletions
17
...ges/react-components/react-skeleton/src/components/SkeletonCircle/SkeletonCircle.types.ts
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,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type SkeletonCircleSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* SkeletonCircle Props | ||
*/ | ||
export type SkeletonCircleProps = ComponentProps<SkeletonCircleSlots> & {}; | ||
|
||
/** | ||
* State used in rendering SkeletonCircle | ||
*/ | ||
export type SkeletonCircleState = ComponentState<SkeletonCircleSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from SkeletonCircleProps. | ||
// & Required<Pick<SkeletonCircleProps, 'propName'>> |
11 changes: 11 additions & 0 deletions
11
...s/react-skeleton/src/components/SkeletonCircle/__snapshots__/SkeletonCircle.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[`SkeletonCircle renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-SkeletonCircle" | ||
> | ||
Default SkeletonCircle | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-skeleton/src/components/SkeletonCircle/index.ts
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,5 @@ | ||
export * from './SkeletonCircle'; | ||
export * from './SkeletonCircle.types'; | ||
export * from './renderSkeletonCircle'; | ||
export * from './useSkeletonCircle'; | ||
export * from './useSkeletonCircleStyles'; |
13 changes: 13 additions & 0 deletions
13
...es/react-components/react-skeleton/src/components/SkeletonCircle/renderSkeletonCircle.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,13 @@ | ||
import * as React from 'react'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import type { SkeletonCircleState, SkeletonCircleSlots } from './SkeletonCircle.types'; | ||
|
||
/** | ||
* Render the final JSX of SkeletonCircle | ||
*/ | ||
export const renderSkeletonCircle_unstable = (state: SkeletonCircleState) => { | ||
const { slots, slotProps } = getSlots<SkeletonCircleSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <slots.root {...slotProps.root} />; | ||
}; |
Oops, something went wrong.