forked from morfeojs/morfeo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devtool: added shadows and opacities slices
- Loading branch information
Showing
11 changed files
with
244 additions
and
6 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
devtool/src/_shared/components/Slices/Opacities/Detail/index.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,23 @@ | ||
import React from 'react'; | ||
import { Opacity, useStyle } from '@morfeo/react'; | ||
import { Card } from '../../../Card'; | ||
import { useRouter } from '../../../../hooks'; | ||
import { RouteState } from '../../../../contexts'; | ||
import { OpacityCard } from '../OpacityCard'; | ||
import styles from './style.module.css'; | ||
|
||
export const Detail: React.FC = () => { | ||
const { route } = useRouter(); | ||
const { state = {} as RouteState } = route; | ||
const { detailKey } = state; | ||
const { opacity } = useStyle({ opacity: detailKey as Opacity }); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<Card className="morfeo-card-primary"> | ||
<OpacityCard opacity={detailKey as Opacity} /> | ||
</Card> | ||
<h2 className="morfeo-typography-h2">opacity: {opacity}</h2> | ||
</div> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
devtool/src/_shared/components/Slices/Opacities/Detail/style.module.css
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,4 @@ | ||
.container { | ||
padding-left: var(--spacings-xs); | ||
padding-right: var(--spacings-xs); | ||
} |
35 changes: 35 additions & 0 deletions
35
devtool/src/_shared/components/Slices/Opacities/OpacityCard.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,35 @@ | ||
import React from 'react'; | ||
import { Opacity, useThemeValue } from '@morfeo/react'; | ||
|
||
type Props = { | ||
opacity: Opacity; | ||
}; | ||
|
||
export const OpacityCard: React.FC<Props> = ({ opacity }) => { | ||
const value = useThemeValue('opacities', opacity); | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="96" | ||
height="96" | ||
fill="none" | ||
viewBox="0 0 96 96" | ||
> | ||
<rect | ||
width="66" | ||
height="66" | ||
x="30" | ||
fill="var(--colors-primary-light)" | ||
rx="5" | ||
></rect> | ||
<rect | ||
width="66" | ||
height="66" | ||
y="30" | ||
fill="var(--colors-primary)" | ||
opacity={value} | ||
rx="5" | ||
></rect> | ||
</svg> | ||
); | ||
}; |
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,56 @@ | ||
import React, { useMemo, useCallback } from 'react'; | ||
import { Opacity, useThemeSlice } from '@morfeo/react'; | ||
import clsx from 'clsx'; | ||
import { Card } from '../../Card'; | ||
import { useRouter } from '../../../hooks/useRouter'; | ||
import { RouteName } from '../../../contexts'; | ||
import { SliceName } from '../../../contexts/Routing/types'; | ||
import { Grid, Item } from '../../Grid'; | ||
import { getSortedSliceValues } from '../../../utils'; | ||
import styles from './style.module.css'; | ||
import { OpacityCard } from './OpacityCard'; | ||
|
||
export { Detail } from './Detail'; | ||
|
||
type Props = { | ||
opacity: Opacity; | ||
}; | ||
|
||
const ItemCard: React.FC<Props> = ({ opacity }) => { | ||
const { navigate } = useRouter(); | ||
|
||
const onClick = useCallback(() => { | ||
navigate(RouteName.SLICE, { | ||
slice: SliceName.OPACITIES, | ||
detailKey: opacity, | ||
}); | ||
}, [opacity, navigate]); | ||
|
||
return ( | ||
<div className={styles.container} onClick={onClick}> | ||
<Card copyText={opacity} className="morfeo-card-primary-clickable"> | ||
<OpacityCard opacity={opacity} /> | ||
</Card> | ||
<h2 className={clsx('morfeo-typography-h2', styles.name)} title={opacity}> | ||
{opacity} | ||
</h2> | ||
</div> | ||
); | ||
}; | ||
|
||
export const OpacitiesSlice: React.FC = () => { | ||
const opacities = useThemeSlice('opacities'); | ||
const keys = getSortedSliceValues(opacities); | ||
|
||
const section = useMemo(() => { | ||
return keys.map(key => { | ||
return ( | ||
<Item key={`opacities-${key}`}> | ||
<ItemCard opacity={key} /> | ||
</Item> | ||
); | ||
}); | ||
}, [keys]); | ||
|
||
return <Grid>{section}</Grid>; | ||
}; |
11 changes: 11 additions & 0 deletions
11
devtool/src/_shared/components/Slices/Opacities/style.module.css
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 @@ | ||
|
||
.container { | ||
width: 100%; | ||
} | ||
|
||
.name { | ||
max-width: 10rem; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} |
32 changes: 32 additions & 0 deletions
32
devtool/src/_shared/components/Slices/Shadows/Detail/index.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,32 @@ | ||
import React from 'react'; | ||
import { Shadow, useStyle } from '@morfeo/react'; | ||
import { Card } from '../../../Card'; | ||
import { useRouter } from '../../../../hooks'; | ||
import { RouteState } from '../../../../contexts'; | ||
import styles from './style.module.css'; | ||
|
||
export const Detail: React.FC = () => { | ||
const { route } = useRouter(); | ||
const { state = {} as RouteState } = route; | ||
const { detailKey } = state; | ||
const { boxShadow } = useStyle({ shadow: detailKey as Shadow }); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<Card className="morfeo-card-primary"> | ||
<Card | ||
className="morfeo-card" | ||
style={ | ||
{ | ||
shadow: detailKey as Shadow, | ||
size: 'var(--sizes-xxl)', | ||
corner: 'var(--radii-xxs)', | ||
bg: 'var(--colors-primary)', | ||
} as any | ||
} | ||
/> | ||
</Card> | ||
<h2 className="morfeo-typography-h2">box-shadow: {boxShadow}</h2> | ||
</div> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
devtool/src/_shared/components/Slices/Shadows/Detail/style.module.css
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,4 @@ | ||
.container { | ||
padding-left: var(--spacings-xs); | ||
padding-right: var(--spacings-xs); | ||
} |
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,62 @@ | ||
import React, { useMemo, useCallback } from 'react'; | ||
import { Shadow, useThemeSlice } from '@morfeo/react'; | ||
import clsx from 'clsx'; | ||
import { Card } from '../../Card'; | ||
import { useRouter } from '../../../hooks/useRouter'; | ||
import { RouteName } from '../../../contexts'; | ||
import { SliceName } from '../../../contexts/Routing/types'; | ||
import { Grid, Item } from '../../Grid'; | ||
import styles from './style.module.css'; | ||
export { Detail } from './Detail'; | ||
|
||
type Props = { | ||
shadow: Shadow; | ||
}; | ||
|
||
const ItemCard: React.FC<Props> = ({ shadow }) => { | ||
const { navigate } = useRouter(); | ||
|
||
const onClick = useCallback(() => { | ||
navigate(RouteName.SLICE, { | ||
slice: SliceName.SHADOWS, | ||
detailKey: shadow, | ||
}); | ||
}, [shadow, navigate]); | ||
|
||
return ( | ||
<div className={styles.container} onClick={onClick}> | ||
<Card copyText={shadow} className="morfeo-card-primary-clickable"> | ||
<Card | ||
style={ | ||
{ | ||
shadow, | ||
size: 'var(--sizes-xl)', | ||
corner: 'var(--radii-xxs)', | ||
bg: 'var(--colors-primary)', | ||
} as any | ||
} | ||
/> | ||
</Card> | ||
<h2 className={clsx('morfeo-typography-h2', styles.name)} title={shadow}> | ||
{shadow} | ||
</h2> | ||
</div> | ||
); | ||
}; | ||
|
||
export const ShadowsSlice: React.FC = () => { | ||
const shadows = useThemeSlice('shadows'); | ||
const keys = Object.keys(shadows) as Shadow[]; | ||
|
||
const section = useMemo(() => { | ||
return keys.map(key => { | ||
return ( | ||
<Item key={`shadows-${key}`}> | ||
<ItemCard shadow={key} /> | ||
</Item> | ||
); | ||
}); | ||
}, [keys]); | ||
|
||
return <Grid>{section}</Grid>; | ||
}; |
11 changes: 11 additions & 0 deletions
11
devtool/src/_shared/components/Slices/Shadows/style.module.css
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 @@ | ||
|
||
.container { | ||
width: 100%; | ||
} | ||
|
||
.name { | ||
max-width: 10rem; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} |
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