-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
211 additions
and
28 deletions.
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
30 changes: 30 additions & 0 deletions
30
devtool/src/_shared/components/Slices/Borders/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,30 @@ | ||
import React from 'react'; | ||
import { Border, morfeo } 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 value = morfeo.resolve({ border: detailKey as Border })['border']; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<Card | ||
className="morfeo-card-primary" | ||
copyText={detailKey} | ||
style={ | ||
{ | ||
border: detailKey as Border, | ||
size: '200px', | ||
} as any | ||
} | ||
> | ||
<h2 className="morfeo-typography-h2">{value}</h2> | ||
</Card> | ||
</div> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
devtool/src/_shared/components/Slices/Borders/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,84 @@ | ||
import React, { useMemo, useCallback } from 'react'; | ||
import { Border, Borders, useThemeSlice } from '@morfeo/react'; | ||
import clsx from 'clsx'; | ||
import { getValueAndUnit } from 'polished'; | ||
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 = { | ||
border: Border; | ||
}; | ||
|
||
const BorderCard: React.FC<Props> = ({ border }) => { | ||
const { navigate } = useRouter(); | ||
|
||
const onClick = useCallback(() => { | ||
navigate(RouteName.SLICE, { | ||
slice: SliceName.BORDERS, | ||
detailKey: border, | ||
}); | ||
}, [border, navigate]); | ||
|
||
return ( | ||
<div className={styles.container} onClick={onClick}> | ||
<Card copyText={border} className="morfeo-card-primary-clickable"> | ||
<Card | ||
style={ | ||
{ | ||
border, | ||
size: 'var(--sizes-xxl)', | ||
} as any | ||
} | ||
/> | ||
</Card> | ||
<h3 className={clsx('morfeo-typography-h2', styles.name)} title={border}> | ||
{border} | ||
</h3> | ||
</div> | ||
); | ||
}; | ||
|
||
function getSortedBorders(borders: Borders) { | ||
const keys = Object.keys(borders) as Border[]; | ||
|
||
return keys.sort((first, second) => { | ||
const [firstValue] = getValueAndUnit( | ||
borders[first].width?.toString() || '0', | ||
); | ||
const [secondValue] = getValueAndUnit( | ||
borders[second].width?.toString() || '0', | ||
); | ||
if (typeof firstValue !== 'number') { | ||
return Infinity; | ||
} | ||
|
||
if (typeof secondValue !== 'number') { | ||
return -Infinity; | ||
} | ||
|
||
return firstValue - secondValue; | ||
}); | ||
} | ||
|
||
export const BordersSlice: React.FC = () => { | ||
const borders = useThemeSlice('borders'); | ||
|
||
const keys = useMemo(() => getSortedBorders(borders || {}), [borders]); | ||
|
||
const section = useMemo(() => { | ||
return keys.map(key => { | ||
return ( | ||
<Item key={`borders-${key}`}> | ||
<BorderCard border={key} /> | ||
</Item> | ||
); | ||
}); | ||
}, [keys]); | ||
|
||
return <Grid>{section}</Grid>; | ||
}; |
11 changes: 11 additions & 0 deletions
11
devtool/src/_shared/components/Slices/Borders/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
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
Oops, something went wrong.