|
| 1 | +import { |
| 2 | + Field, |
| 3 | + makeStyles, |
| 4 | + tokens, |
| 5 | + Switch, |
| 6 | + PresenceComponentProps, |
| 7 | + Skeleton, |
| 8 | + SkeletonItem, |
| 9 | +} from '@fluentui/react-components'; |
| 10 | +import { |
| 11 | + Blur, |
| 12 | + Collapse, |
| 13 | + CollapseDelayed, |
| 14 | + CollapseRelaxed, |
| 15 | + ScaleRelaxed, |
| 16 | + Slide, |
| 17 | + SlideRelaxed, |
| 18 | +} from '@fluentui/react-motion-components-preview'; |
| 19 | +import * as React from 'react'; |
| 20 | +import { PresenceStagger, Stagger } from '../Experiments/Stagger'; |
| 21 | +import { SlideUnder } from '../Experiments/SlideUnder'; |
| 22 | +import { Hold, Series } from '../Experiments/Series'; |
| 23 | + |
| 24 | +const useClasses = makeStyles({ |
| 25 | + container: { |
| 26 | + display: 'grid', |
| 27 | + gridTemplate: `"controls ." "card card" / 1fr 1fr`, |
| 28 | + gap: '20px 10px', |
| 29 | + }, |
| 30 | + card: { |
| 31 | + gridArea: 'card', |
| 32 | + padding: '10px', |
| 33 | + overflow: 'hidden', |
| 34 | + }, |
| 35 | + controls: { |
| 36 | + display: 'flex', |
| 37 | + flexDirection: 'column', |
| 38 | + gridArea: 'controls', |
| 39 | + |
| 40 | + border: `${tokens.strokeWidthThicker} solid ${tokens.colorNeutralForeground3}`, |
| 41 | + borderRadius: tokens.borderRadiusMedium, |
| 42 | + boxShadow: tokens.shadow16, |
| 43 | + padding: '10px', |
| 44 | + }, |
| 45 | + field: { |
| 46 | + flex: 1, |
| 47 | + }, |
| 48 | +}); |
| 49 | + |
| 50 | +const useStyles = makeStyles({ |
| 51 | + invertedWrapper: { |
| 52 | + backgroundColor: tokens.colorNeutralBackground1, |
| 53 | + }, |
| 54 | + firstRow: { |
| 55 | + alignItems: 'center', |
| 56 | + display: 'grid', |
| 57 | + paddingBottom: '10px', |
| 58 | + position: 'relative', |
| 59 | + gap: '10px', |
| 60 | + gridTemplateColumns: 'min-content 80%', |
| 61 | + }, |
| 62 | + secondThirdRow: { |
| 63 | + alignItems: 'center', |
| 64 | + display: 'grid', |
| 65 | + paddingBottom: '10px', |
| 66 | + position: 'relative', |
| 67 | + gap: '10px', |
| 68 | + gridTemplateColumns: 'min-content 20% 20% 15% 15%', |
| 69 | + }, |
| 70 | +}); |
| 71 | + |
| 72 | +const LoremIpsum = () => ( |
| 73 | + <> |
| 74 | + {'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '.repeat( |
| 75 | + 10, |
| 76 | + )} |
| 77 | + </> |
| 78 | +); |
| 79 | + |
| 80 | +export const ExperimentsStaggerSkeleton = (props: React.ComponentProps<typeof Collapse>) => { |
| 81 | + const classes = useClasses(); |
| 82 | + const styles = useStyles(); |
| 83 | + |
| 84 | + const [visible, setVisible] = React.useState<boolean>(false); |
| 85 | + |
| 86 | + const RowMotion = () => ( |
| 87 | + <Slide.In> |
| 88 | + <div className={styles.firstRow}> |
| 89 | + <SkeletonItem shape="circle" size={24} /> |
| 90 | + <SkeletonItem shape="rectangle" size={16} /> |
| 91 | + </div> |
| 92 | + </Slide.In> |
| 93 | + ); |
| 94 | + |
| 95 | + const SkeletonRowCustom = () => ( |
| 96 | + <div className={styles.firstRow}> |
| 97 | + <SkeletonItem shape="circle" size={28} /> |
| 98 | + <SkeletonItem shape="rectangle" size={20} /> |
| 99 | + </div> |
| 100 | + ); |
| 101 | + |
| 102 | + const ContentRow = ({ |
| 103 | + index = 0, |
| 104 | + text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', |
| 105 | + }: { index?: number; text?: string } = {}) => ( |
| 106 | + <div key={index} className={styles.firstRow}> |
| 107 | + <div style={{ width: '28px', height: '28px', backgroundColor: 'grey', borderRadius: '50%' }} /> |
| 108 | + <div style={{ width: '100%', height: '28px', paddingTop: '5px' }}>{text}</div> |
| 109 | + </div> |
| 110 | + ); |
| 111 | + |
| 112 | + const ContentRowPresence = ({ visible = false }: { visible?: boolean }) => ( |
| 113 | + // <ScaleRelaxed visible={visible} duration={1000}> |
| 114 | + // <div> |
| 115 | + // <Blur visible={visible} enterDuration={700} radius="50px"> |
| 116 | + <SlideUnder visible={visible}> |
| 117 | + <div className={styles.firstRow}> |
| 118 | + {visible ? <ContentRow /> : <div style={{ width: '100%', height: '28px' }} />} |
| 119 | + </div> |
| 120 | + </SlideUnder> |
| 121 | + // </Blur> |
| 122 | + // </div> |
| 123 | + // </ScaleRelaxed> |
| 124 | + ); |
| 125 | + |
| 126 | + const SkeletonRowPresence = ({ visible = false }: { visible?: boolean }) => ( |
| 127 | + // <ScaleRelaxed visible={visible} duration={1000}> |
| 128 | + // <div> |
| 129 | + // <Blur visible={visible} enterDuration={700} radius="50px"> |
| 130 | + <SlideUnder visible={visible}> |
| 131 | + {visible ? ( |
| 132 | + <div style={{ height: '36px' }}> |
| 133 | + <Series> |
| 134 | + <Hold duration={3000}> |
| 135 | + <SkeletonRowCustom /> |
| 136 | + </Hold> |
| 137 | + <Slide.In>{ContentRow()}</Slide.In> |
| 138 | + </Series> |
| 139 | + </div> |
| 140 | + ) : ( |
| 141 | + <div style={{ width: '100%', height: '36px' }} /> |
| 142 | + )} |
| 143 | + </SlideUnder> |
| 144 | + // </Blur> |
| 145 | + // </div> |
| 146 | + // </ScaleRelaxed> |
| 147 | + ); |
| 148 | + |
| 149 | + return ( |
| 150 | + <div className={classes.container}> |
| 151 | + <div className={classes.controls}> |
| 152 | + <Field className={classes.field}> |
| 153 | + <Switch label="Visible" checked={visible} onChange={() => setVisible(v => !v)} /> |
| 154 | + </Field> |
| 155 | + </div> |
| 156 | + |
| 157 | + <CollapseDelayed visible={visible} unmountOnExit animateOpacity={false}> |
| 158 | + <div className={classes.card}> |
| 159 | + { |
| 160 | + <Skeleton> |
| 161 | + <PresenceStagger delay={70} mode={visible ? 'enterReverse' : 'exitReverse'}> |
| 162 | + <SkeletonRowPresence /> |
| 163 | + <SkeletonRowPresence /> |
| 164 | + <SkeletonRowPresence /> |
| 165 | + <SkeletonRowPresence /> |
| 166 | + <SkeletonRowPresence /> |
| 167 | + <SkeletonRowPresence /> |
| 168 | + <SkeletonRowPresence /> |
| 169 | + <SkeletonRowPresence /> |
| 170 | + </PresenceStagger> |
| 171 | + </Skeleton> |
| 172 | + } |
| 173 | + </div> |
| 174 | + </CollapseDelayed> |
| 175 | + </div> |
| 176 | + ); |
| 177 | +}; |
| 178 | + |
| 179 | +ExperimentsStaggerSkeleton.parameters = { |
| 180 | + docs: { |
| 181 | + description: { |
| 182 | + // story: description, |
| 183 | + }, |
| 184 | + }, |
| 185 | +}; |
0 commit comments