Skip to content

Commit

Permalink
feat: added borders slice
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed Oct 25, 2021
1 parent 3d283ed commit 3cc7c5c
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { CodeTab } from '../types';
type Params = {
slice: ThemeKey;
value: string;
htmlTag?: string;
property: string;
cssProperty?: string;
};

export function general({
slice,
value,
htmlTag = 'div',
property,
cssProperty,
}: Params): CodeTab[] {
Expand Down Expand Up @@ -39,5 +41,12 @@ export function general({
label: 'CSS',
language: 'css',
},
{
code: `<${htmlTag} class="${paramCase(property)}-${paramCase(
value || '',
)}" />`,
label: 'HTML',
language: 'html',
},
];
}
4 changes: 3 additions & 1 deletion devtool/src/_shared/components/DropDown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const DropDown: React.FC<Props> = ({
className={styles.option}
onClick={getOnClick(optionValue)}
>
<h4 className="morfeo-typography-h4 ml-xs">{optionLabel}</h4>
<h4 className="morfeo-typography-h4 color-text-color ml-xs">
{optionLabel}
</h4>
</div>
));
}, [options, getOnClick]);
Expand Down
30 changes: 30 additions & 0 deletions devtool/src/_shared/components/Slices/Borders/Detail/index.tsx
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>
);
};
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);
}
84 changes: 84 additions & 0 deletions devtool/src/_shared/components/Slices/Borders/index.tsx
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 devtool/src/_shared/components/Slices/Borders/style.module.css
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;
}
5 changes: 3 additions & 2 deletions devtool/src/_shared/components/Slices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RadiiSlice, Detail as RadiusDetail } from './Radii';
import { Colors, Detail as ColorDetail } from './Colors';
import { Gradients, Detail as GradientDetail } from './Gradients';
import { Components, Detail as ComponentDetail } from './Components';
import { BordersSlice, Detail as BorderDetail } from './Borders';

export type SliceConfig = {
render: React.FC;
Expand Down Expand Up @@ -42,8 +43,8 @@ export const slices: Record<SliceName, SliceConfig> = {
displayName: 'shadows',
},
[SliceName.BORDERS]: {
render: () => <></>,
renderDetail: () => <></>,
render: () => <BordersSlice />,
renderDetail: () => <BorderDetail />,
displayName: 'borders',
},
[SliceName.SPACINGS]: {
Expand Down
64 changes: 64 additions & 0 deletions devtool/src/_shared/css/classes.css
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,14 @@
.height-xxs {
height: var(--sizes-xxs);
}
.min-size-xxs {
min-width: var(--sizes-xxs);
min-height: var(--sizes-xxs);
}
.max-size-xxs {
max-width: var(--sizes-xxs);
max-height: var(--sizes-xxs);
}
.min-width-xxs {
min-width: var(--sizes-xxs);
}
Expand Down Expand Up @@ -1250,6 +1258,14 @@
.height-xs {
height: var(--sizes-xs);
}
.min-size-xs {
min-width: var(--sizes-xs);
min-height: var(--sizes-xs);
}
.max-size-xs {
max-width: var(--sizes-xs);
max-height: var(--sizes-xs);
}
.min-width-xs {
min-width: var(--sizes-xs);
}
Expand Down Expand Up @@ -1293,6 +1309,14 @@
.height-s {
height: var(--sizes-s);
}
.min-size-s {
min-width: var(--sizes-s);
min-height: var(--sizes-s);
}
.max-size-s {
max-width: var(--sizes-s);
max-height: var(--sizes-s);
}
.min-width-s {
min-width: var(--sizes-s);
}
Expand Down Expand Up @@ -1336,6 +1360,14 @@
.height-m {
height: var(--sizes-m);
}
.min-size-m {
min-width: var(--sizes-m);
min-height: var(--sizes-m);
}
.max-size-m {
max-width: var(--sizes-m);
max-height: var(--sizes-m);
}
.min-width-m {
min-width: var(--sizes-m);
}
Expand Down Expand Up @@ -1379,6 +1411,14 @@
.height-l {
height: var(--sizes-l);
}
.min-size-l {
min-width: var(--sizes-l);
min-height: var(--sizes-l);
}
.max-size-l {
max-width: var(--sizes-l);
max-height: var(--sizes-l);
}
.min-width-l {
min-width: var(--sizes-l);
}
Expand Down Expand Up @@ -1422,6 +1462,14 @@
.height-xl {
height: var(--sizes-xl);
}
.min-size-xl {
min-width: var(--sizes-xl);
min-height: var(--sizes-xl);
}
.max-size-xl {
max-width: var(--sizes-xl);
max-height: var(--sizes-xl);
}
.min-width-xl {
min-width: var(--sizes-xl);
}
Expand Down Expand Up @@ -1465,6 +1513,14 @@
.height-xxl {
height: var(--sizes-xxl);
}
.min-size-xxl {
min-width: var(--sizes-xxl);
min-height: var(--sizes-xxl);
}
.max-size-xxl {
max-width: var(--sizes-xxl);
max-height: var(--sizes-xxl);
}
.min-width-xxl {
min-width: var(--sizes-xxl);
}
Expand Down Expand Up @@ -1508,6 +1564,14 @@
.height-none {
height: var(--sizes-none);
}
.min-size-none {
min-width: var(--sizes-none);
min-height: var(--sizes-none);
}
.max-size-none {
max-width: var(--sizes-none);
max-height: var(--sizes-none);
}
.min-width-none {
min-width: var(--sizes-none);
}
Expand Down
11 changes: 0 additions & 11 deletions devtool/src/_shared/css/dark-components.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,67 +105,57 @@
background-color: var(--colors-success);
}
[data-morfeo-theme="dark"] .morfeo-typography {
color: var(--colors-text-color);
font-family: var(--fonts-regular);
}
[data-morfeo-theme="dark"] .morfeo-typography-hero {
color: var(--colors-text-color);
font-size: var(--font-sizes-l);
font-family: var(--fonts-regular);
font-weight: var(--font-weights-bold);
line-height: var(--line-heights-heading);
}
[data-morfeo-theme="dark"] .morfeo-typography-h1 {
color: var(--colors-text-color);
font-size: var(--font-sizes-xl);
font-family: var(--fonts-regular);
font-weight: var(--font-weights-bold);
line-height: var(--line-heights-heading);
letter-spacing: var(--letter-spacings-heading);
}
[data-morfeo-theme="dark"] .morfeo-typography-h2 {
color: var(--colors-text-color);
font-size: var(--font-sizes-m);
font-family: var(--fonts-regular);
font-weight: var(--font-weights-bold);
line-height: var(--line-heights-heading);
}
[data-morfeo-theme="dark"] .morfeo-typography-h3 {
color: var(--colors-text-color);
font-size: var(--font-sizes-s);
font-family: var(--fonts-regular);
font-weight: var(--font-weights-bold);
line-height: var(--line-heights-heading);
}
[data-morfeo-theme="dark"] .morfeo-typography-h4 {
color: var(--colors-text-color);
font-size: var(--font-sizes-s);
font-family: var(--fonts-regular);
font-weight: var(--font-weights-bold);
line-height: var(--line-heights-heading);
}
[data-morfeo-theme="dark"] .morfeo-typography-p1 {
color: var(--colors-text-color);
font-size: var(--font-sizes-m);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
letter-spacing: var(--letter-spacings-body);
}
[data-morfeo-theme="dark"] .morfeo-typography-p2 {
color: var(--colors-text-color);
font-size: var(--font-sizes-s);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
letter-spacing: var(--letter-spacings-body);
}
[data-morfeo-theme="dark"] .morfeo-typography-p3 {
color: var(--colors-text-color);
font-size: var(--font-sizes-xs);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
}
[data-morfeo-theme="dark"] .morfeo-typography-p4 {
color: var(--colors-text-color);
font-size: var(--font-sizes-xxs);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
Expand All @@ -181,7 +171,6 @@
color: var(--colors-primary-lightest);
}
[data-morfeo-theme="dark"] .morfeo-typography-caption {
color: var(--colors-text-color);
font-size: var(--font-sizes-xxs);
font-style: italic;
font-family: var(--fonts-regular);
Expand Down
Loading

0 comments on commit 3cc7c5c

Please sign in to comment.