-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add new feature for Size and Shape for Skeleton. #32455
Open
shethaadit
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
shethaadit:shethaadt/SkeletonPropsNewFeature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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
154 changes: 152 additions & 2 deletions
154
...act-components/react-skeleton/library/src/components/Skeleton/useSkeletonStyles.styles.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 |
---|---|---|
@@ -1,17 +1,167 @@ | ||
import { mergeClasses } from '@griffel/react'; | ||
import { makeStyles, mergeClasses } from '@griffel/react'; | ||
import type { SkeletonSlots, SkeletonState } from './Skeleton.types'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import { tokens } from '@fluentui/react-theme'; | ||
|
||
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. Why do you need to change styles? This feature requires only to pass |
||
export const skeletonClassNames: SlotClassNames<SkeletonSlots> = { | ||
root: 'fui-Skeleton', | ||
}; | ||
|
||
const skeletonWaveAnimation = { | ||
to: { | ||
transform: 'translate(100%)', | ||
}, | ||
}; | ||
|
||
const skeletonPulseAnimation = { | ||
'0%': { | ||
opacity: '1', | ||
}, | ||
'50%': { | ||
opacity: '0.4', | ||
}, | ||
'100%': { | ||
opacity: '1', | ||
}, | ||
}; | ||
|
||
/** | ||
* Styles for the root slot | ||
*/ | ||
const useStyles = makeStyles({ | ||
root: { | ||
position: 'relative', | ||
overflow: 'hidden', | ||
|
||
'::after': { | ||
content: '""', | ||
display: 'block', | ||
position: 'absolute', | ||
inset: '0', | ||
animationIterationCount: 'infinite', | ||
animationDuration: '3s', | ||
animationTimingFunction: 'ease-in-out', | ||
'@media screen and (prefers-reduced-motion: reduce)': { | ||
animationDuration: '0.01ms', | ||
animationIterationCount: '1', | ||
}, | ||
}, | ||
}, | ||
wave: { | ||
backgroundColor: tokens.colorNeutralStencil1, | ||
|
||
'::after': { | ||
animationName: skeletonWaveAnimation, | ||
backgroundImage: `linear-gradient( | ||
to right, | ||
${tokens.colorNeutralStencil1} 0%, | ||
${tokens.colorNeutralStencil2} 50%, | ||
${tokens.colorNeutralStencil1} 100%)`, | ||
transform: 'translate(-100%)', | ||
|
||
'@media screen and (forced-colors: active)': { | ||
backgroundColor: 'WindowText', | ||
}, | ||
}, | ||
}, | ||
pulse: { | ||
'::after': { | ||
animationName: skeletonPulseAnimation, | ||
animationDuration: '1s', | ||
backgroundColor: tokens.colorNeutralStencil1, | ||
}, | ||
}, | ||
translucent: { | ||
backgroundColor: tokens.colorNeutralStencil1Alpha, | ||
|
||
'::after': { | ||
backgroundImage: `linear-gradient( | ||
to right, | ||
transparent 0%, | ||
${tokens.colorNeutralStencil1Alpha} 50%, | ||
transparent 100%)`, | ||
}, | ||
}, | ||
translucentPulse: { | ||
backgroundColor: 'none', | ||
|
||
'::after': { | ||
backgroundColor: tokens.colorNeutralStencil1Alpha, | ||
}, | ||
}, | ||
}); | ||
|
||
const useRectangleStyles = makeStyles({ | ||
root: { | ||
width: '100%', | ||
borderRadius: '4px', | ||
}, | ||
8: { height: '8px' }, | ||
12: { height: '12px' }, | ||
16: { height: '16px' }, | ||
20: { height: '20px' }, | ||
24: { height: '24px' }, | ||
28: { height: '28px' }, | ||
32: { height: '32px' }, | ||
36: { height: '36px' }, | ||
40: { height: '40px' }, | ||
48: { height: '48px' }, | ||
56: { height: '56px' }, | ||
64: { height: '64px' }, | ||
72: { height: '72px' }, | ||
96: { height: '96px' }, | ||
120: { height: '120px' }, | ||
128: { height: '128px' }, | ||
}); | ||
|
||
const useSizeStyles = makeStyles({ | ||
8: { width: '8px', height: '8px' }, | ||
12: { width: '12px', height: '12px' }, | ||
16: { width: '16px', height: '16px' }, | ||
20: { width: '20px', height: '20px' }, | ||
24: { width: '24px', height: '24px' }, | ||
28: { width: '28px', height: '28px' }, | ||
32: { width: '32px', height: '32px' }, | ||
36: { width: '36px', height: '36px' }, | ||
40: { width: '40px', height: '40px' }, | ||
48: { width: '48px', height: '48px' }, | ||
56: { width: '56px', height: '56px' }, | ||
64: { width: '64px', height: '64px' }, | ||
72: { width: '72px', height: '72px' }, | ||
96: { width: '96px', height: '96px' }, | ||
120: { width: '120px', height: '120px' }, | ||
128: { width: '128px', height: '128px' }, | ||
}); | ||
|
||
const useCircleSizeStyles = makeStyles({ | ||
root: { | ||
borderRadius: '50%', | ||
}, | ||
}); | ||
|
||
/** | ||
* Apply styling to the Skeleton slots based on the state | ||
*/ | ||
export const useSkeletonStyles_unstable = (state: SkeletonState): SkeletonState => { | ||
'use no memo'; | ||
|
||
state.root.className = mergeClasses(skeletonClassNames.root, state.root.className); | ||
const { size, shape } = state; | ||
|
||
const rootStyles = useStyles(); | ||
const rectStyles = useRectangleStyles(); | ||
const sizeStyles = useSizeStyles(); | ||
const circleStyles = useCircleSizeStyles(); | ||
|
||
state.root.className = mergeClasses( | ||
skeletonClassNames.root, | ||
rootStyles.root, | ||
shape === 'rectangle' && rectStyles.root, | ||
shape === 'rectangle' && rectStyles[size], | ||
shape === 'square' && sizeStyles[size], | ||
shape === 'circle' && circleStyles.root, | ||
shape === 'circle' && sizeStyles[size], | ||
state.root.className, | ||
); | ||
|
||
return state; | ||
}; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be good to import existing
SkeletonItemSize
or to import this type inSkeletonItem.types.ts
. Currently it duplicatesSkeletonItemSize