Skip to content

Commit

Permalink
Merge pull request morfeojs#94 from VLK-STUDIO/feat/93
Browse files Browse the repository at this point in the history
Feat/93
  • Loading branch information
mauroerta authored Oct 30, 2021
2 parents d021562 + 066639a commit 727d683
Show file tree
Hide file tree
Showing 56 changed files with 301 additions and 386 deletions.
3 changes: 0 additions & 3 deletions devtool/public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
"headerMyThemesPlaceholder": {
"message": "Select..."
},
"sliceCodeTitle": {
"message": "Code snippet"
},
"sidebarDocs": {
"message": "Docs"
},
Expand Down
3 changes: 0 additions & 3 deletions devtool/public/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
"headerMyThemesPlaceholder": {
"message": "Seleziona..."
},
"sliceCodeTitle": {
"message": "Snippet di codice"
},
"sidebarDocs": {
"message": "Docs"
},
Expand Down
6 changes: 3 additions & 3 deletions devtool/src/_shared/components/Accordion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export const Accordion: React.FC<Props> = ({
className={styles.icon}
/>
)}
<h4
className="morfeo-typography-h1"
<h2
className="morfeo-typography-h2"
style={{ color: 'var(--color-inverted-text-color)' }}
>
{label}
</h4>
</h2>
</div>
</div>
<div className={styles.content}>{children}</div>
Expand Down
2 changes: 0 additions & 2 deletions devtool/src/_shared/components/CodeSnippets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Code } from '../Code';
import styles from './style.module.css';
import { ThemeKey } from '@morfeo/react';
import { getCodeSnippets } from './snippets';
import { t } from '../../utils';

type Props = {
slice: ThemeKey;
Expand Down Expand Up @@ -56,7 +55,6 @@ export const CodeSnippets: React.FC<Props> = ({

return (
<>
<h1 className="morfeo-typography-h1">{t('sliceCodeTitle')}</h1>
<div className={styles.header}>{renderedHeaders}</div>
<div>{currentCode}</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion devtool/src/_shared/components/DropDown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const DropDown: React.FC<Props> = ({
)}
>
{title && (
<h3 className={clsx('morfeo-typography-h3', styles.title)}>{title}</h3>
<h4 className={clsx('morfeo-typography-h4', styles.title)}>{title}</h4>
)}
<div className={styles.buttonContainer}>
<button
Expand Down
1 change: 1 addition & 0 deletions devtool/src/_shared/components/DropDown/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
align-items: center;
justify-content: space-between;
background-color: var(--colors-background) !important;
font-size: var(--font-sizes-s) !important;
}

.inverted .button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { getContrast } from 'polished';
import { Card } from '../../../Card';
import { Props as DetailProps } from '../Detail';
import { BorderSlice } from '../index';
import { DetailLabel } from '../../../DetailLabel';
import { DetailLabel } from '../../_shared/DetailLabel';
import { ListItemCard } from '../../_shared/ListItemCard';

export type Props = {
clickable?: boolean;
detailKey: string;
showValues?: boolean;
mainSlice: DetailProps['mainSlice'];
filters?: Record<'borderWidths' | 'borderStyles' | 'colors', string>;
showTitle?: boolean;
};

const propertiesMap: Record<BorderSlice, keyof React.CSSProperties> = {
Expand All @@ -26,6 +28,7 @@ export const BorderCard: React.FC<Props> = ({
showValues,
mainSlice,
filters,
showTitle,
}) => {
const isBorders = mainSlice === 'borders';
const themeValue = useThemeValue(mainSlice, detailKey as any);
Expand Down Expand Up @@ -76,20 +79,21 @@ export const BorderCard: React.FC<Props> = ({

return (
<>
<Card
className={`${
clickable ? 'morfeo-card-primary-clickable' : 'morfeo-card-primary'
} ${contrastRatio < 1.95 ? 'bg-black' : 'bg-white'}`}
<ListItemCard
title={showTitle ? detailKey : ''}
clickable={clickable}
mode={contrastRatio < 1.95 ? 'dark' : 'light'}
copyText={detailKey}
>
<Card
style={
{
...innerCardStyle,
size: '100%',
size: '100px',
} as any
}
/>
</Card>
</ListItemCard>
{showValues && (
<DetailLabel value={(style as any)[propertiesMap[mainSlice]]} />
)}
Expand Down
5 changes: 1 addition & 4 deletions devtool/src/_shared/components/Slices/Borders/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useMemo, useCallback } from 'react';
import { Border, Borders, useThemeSlice } from '@morfeo/react';
import clsx from 'clsx';
import { getValueAndUnit } from 'polished';
import { useRouter } from '../../../hooks/useRouter';
import { RouteName } from '../../../contexts';
Expand Down Expand Up @@ -37,13 +36,11 @@ const BorderListItem: React.FC<Props> = ({ value }) => {
return (
<div className={styles.container} onClick={onClick}>
<BorderCard
showTitle
mainSlice={state?.slice as BorderSlice}
detailKey={value}
clickable
/>
<h3 className={clsx('morfeo-typography-h2', styles.name)} title={value}>
{value}
</h3>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Color, useStyle } from '@morfeo/react';
import { Card } from '../../../Card';
import { useRouter } from '../../../../hooks';
import styles from './style.module.css';
import { DetailLabel } from '../../../DetailLabel';
import { DetailLabel } from '../../_shared/DetailLabel';

function hex2rgba(code: string) {
let hex = code.replace(/[^0-9a-fA-F]/g, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
.colorsCodesContainer {
display: flex;
align-items: center;
margin-top: var(--spacings-xs);
margin-bottom: var(--spacings-xs);
justify-content: space-between;
}
44 changes: 16 additions & 28 deletions devtool/src/_shared/components/Slices/Colors/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { useMemo } from 'react';
import { Color, useTheme } from '@morfeo/react';
import clsx from 'clsx';
import { getContrast } from 'polished';
import { Card } from '../../Card';
import styles from './style.module.css';
import { useRouter } from '../../../hooks/useRouter';
import { RouteName } from '../../../contexts';
import { SliceName } from '../../../contexts/Routing/types';
import { Grid, Item } from '../../Grid';
import { ListItemCard } from '../_shared/ListItemCard';
export { Detail } from './Detail';

export const Colors: React.FC = () => {
Expand All @@ -29,42 +27,32 @@ export const Colors: React.FC = () => {

return (
<Item key={`colors-${key}`}>
<div
key={`colors-${key}`}
className={styles.colorContainer}
<ListItemCard
onClick={() =>
navigate(RouteName.SLICE, {
slice: SliceName.COLORS,
detailKey: key,
})
}
title={key}
clickable
style={{
bg: key as Color
}}
copyText={key}
>
<Card
copyText={key}
className="morfeo-card-primary-clickable"
<h3
className="morfeo-typography-h3"
style={{
bg: key,
color:
contrastRatio < 1.95
? 'var(--colors-gray-darkest)'
: 'var(--colors-gray-lightest)',
}}
>
<h2
className="morfeo-typography-h2"
style={{
color:
contrastRatio < 1.95
? 'var(--colors-gray-darkest)'
: 'var(--colors-gray-lightest)',
}}
>
{slice[key]}
</h2>
</Card>
<h3
className={clsx('morfeo-typography-h2', styles.colorName)}
title={key}
>
{key}
{slice[key]}
</h3>
</div>
</ListItemCard>
</Item>
);
});
Expand Down
18 changes: 0 additions & 18 deletions devtool/src/_shared/components/Slices/Colors/style.module.css

This file was deleted.

8 changes: 4 additions & 4 deletions devtool/src/_shared/components/Slices/Components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const Info: React.FC<Props> = ({ name, variant }) => {
return (
<div className={styles.infoContainer}>
<div className={styles.infoHeader}>
<h2
className={clsx('morfeo-typography-h2', styles.componentName)}
<h3
className={clsx('morfeo-typography-h3', styles.componentName)}
title={variant || name}
>
{variant || name}
</h2>
</h3>
{numberOfVariants > 0 && !variant && (
<p className={clsx('morfeo-typography-p1', styles.componentName)}>
<p className={clsx('morfeo-typography-p2', styles.componentName)}>
{numberOfVariants} variants
</p>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Tags: React.FC<Props> = ({ name, variant }) => {

return (
<div className={styles.infoTags}>
<p className={clsx('morfeo-typography-p1', styles.tag)}>
<p className={clsx('morfeo-typography-p2', styles.tag)}>
{tags.length > 0 ? `#${tags.join(' #')}` : ''}
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
width: 100%;
height: 125px;
box-shadow: none;
max-width: 100%;
overflow: hidden;
}

.infoContainer {
Expand Down
18 changes: 14 additions & 4 deletions devtool/src/_shared/components/Slices/Fonts/Detail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useCallback, useMemo } from 'react';
import { morfeo, useStyle } from '@morfeo/react';
import { morfeo, useStyle, useThemeSlice, Font } from '@morfeo/react';
import { capitalCase, noCase, paramCase } from 'change-case';
import clsx from 'clsx';
import { Card } from '../../../Card';
Expand All @@ -9,7 +9,7 @@ import styles from './style.module.css';
import { Input } from '../../../Input';
import { DropDown } from '../../../DropDown';
import { t } from '../../../../utils';
import { DetailLabel } from '../../../DetailLabel';
import { DetailLabel } from '../../_shared/DetailLabel';

const fontSlices = [
'fonts',
Expand All @@ -19,7 +19,7 @@ const fontSlices = [
'lineHeights',
] as const;

const propertiesMap = {
export const propertiesMap = {
fonts: 'fontFamily',
fontSizes: 'fontSize',
fontWeights: 'fontWeight',
Expand All @@ -45,6 +45,12 @@ export const Detail: React.FC<Props> = ({ main = 'fonts' }) => {
);
const { state = {} as RouteState } = route;
const { detailKey } = state;
const themeFonts = useThemeSlice('fonts')

const firstFont = useMemo(() => {
const fontArray = Object.keys(themeFonts)
return fontArray[0] as Font
}, [themeFonts])

const filteredFontSlices = useMemo(
() => fontSlices.filter(slice => slice !== main),
Expand All @@ -54,11 +60,15 @@ export const Detail: React.FC<Props> = ({ main = 'fonts' }) => {
[propertiesMap[main]]: detailKey,
...filteredFontSlices.reduce((acc, curr) => {
if (filtersState[curr]) {
return { ...acc, [propertiesMap[curr]]: filtersState[curr] };
return {
...acc,
[propertiesMap[curr]]: filtersState[curr],
};
}

return acc;
}, {}),
...firstFont && main !== 'fonts' && { fontFamily: firstFont as Font }
};
const fontStyle = useStyle(style);

Expand Down
23 changes: 14 additions & 9 deletions devtool/src/_shared/components/Slices/Fonts/General.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useMemo, useCallback } from 'react';
import { Font, useStyle, ThemeKey, useThemeSlice } from '@morfeo/react';
import { Card } from '../../Card';
import { Font, useStyle, ThemeKey, useThemeSlice, Fonts, useTheme } from '@morfeo/react';
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';
import { ListItemCard } from '../_shared/ListItemCard';

export { Detail } from './Detail';

Expand All @@ -20,8 +20,16 @@ type Props = {

const ItemCard: React.FC<ItemProps> = ({ property, value }) => {
const { navigate, route } = useRouter();
const themeFonts = useTheme().fonts;

const firstFont = useMemo(() => {
const fontArray = Object.keys(themeFonts)
return fontArray[0] as keyof Fonts
}, [themeFonts])

const fontStyle = useStyle({
[property]: value,
...firstFont && property !== 'fontFamily' && { fontFamily: firstFont }
});

const onClick = useCallback(() => {
Expand All @@ -32,14 +40,11 @@ const ItemCard: React.FC<ItemProps> = ({ property, value }) => {
}, [navigate, route.state?.slice, value]);

return (
<div className={styles.container} onClick={onClick}>
<Card copyText={value} className="morfeo-card-primary-clickable">
<h1 className={styles.name} title={value} style={fontStyle as any}>
<ListItemCard title={value} onClick={onClick} mode='light' clickable>
<h1 className={styles.name} title={value} style={fontStyle as any}>
Aa
</h1>
</Card>
<h2 className="morfeo-typography-h2">{value}</h2>
</div>
</h1>
</ListItemCard>
);
};

Expand Down
Loading

0 comments on commit 727d683

Please sign in to comment.