diff --git a/devtool/src/_shared/components/Grid/Item/style.module.css b/devtool/src/_shared/components/Grid/Item/style.module.css
index 1c4ddbac..67e68110 100644
--- a/devtool/src/_shared/components/Grid/Item/style.module.css
+++ b/devtool/src/_shared/components/Grid/Item/style.module.css
@@ -6,6 +6,7 @@
min-width: 25%;
box-sizing: border-box;
position: relative;
+ flex-grow: 1;
}
@media screen and (min-width: 375px) {
diff --git a/devtool/src/_shared/components/Slices/Components/Detail/index.tsx b/devtool/src/_shared/components/Slices/Components/Detail/index.tsx
index d2e73e5c..e61d82fa 100644
--- a/devtool/src/_shared/components/Slices/Components/Detail/index.tsx
+++ b/devtool/src/_shared/components/Slices/Components/Detail/index.tsx
@@ -1,30 +1,64 @@
-import { Component } from '@morfeo/react';
+import { Color, Component, component, morfeo } from '@morfeo/react';
import clsx from 'clsx';
+import { useMemo, useState, useCallback } from 'react';
import { useRouter } from '../../../../hooks';
import { MorfeoComponent } from '../MorfeoComponent';
-
import styles from './style.module.css';
+import { Card } from '../../../Card';
+import { Icon } from '../../../Icon';
export const Detail = () => {
const { route } = useRouter();
const { state } = route;
const { detailKey: componentName = '', componentVariant } = state || {};
+ const { meta } =
+ component(componentName as Component, componentVariant).get() || {};
+ const { devtoolConfig } = meta || {};
+ const [defaultStyleActive, setDefaultStyleActive] = useState(true);
+
+ const currentThemeName = morfeo.getCurrent();
+
+ const computedBackground = useMemo(() => {
+ if (typeof devtoolConfig?.background === 'object') {
+ return devtoolConfig?.background[currentThemeName];
+ }
+ return (devtoolConfig?.background as Color) || ('#fff' as Color);
+ }, [currentThemeName, devtoolConfig?.background]);
+
+ const onDefaultStyleCheckboxChange = useCallback(() => {
+ setDefaultStyleActive(state => !state);
+ }, [])
return (
-
+
+
+
+
+
+ Web extension default style
+
+
+
+
+
+ )}
+
{componentName}
-
+
);
};
diff --git a/devtool/src/_shared/components/Slices/Components/Detail/style.module.css b/devtool/src/_shared/components/Slices/Components/Detail/style.module.css
index ea6c3962..1d5a96a3 100644
--- a/devtool/src/_shared/components/Slices/Components/Detail/style.module.css
+++ b/devtool/src/_shared/components/Slices/Components/Detail/style.module.css
@@ -3,6 +3,16 @@
padding-right: var(--spacings-xs);
}
+.defaultStyleAlertContainer {
+ display: flex;
+ align-items: center;
+ margin-bottom: var(--spacings-xxs);
+}
+
+.icon {
+ margin-right: var(--spacings-xxs);
+}
+
.previewContainer {
width: 100%;
padding-top: var(--spacings-xxl);
diff --git a/devtool/src/_shared/components/Slices/Components/MorfeoComponent.ts b/devtool/src/_shared/components/Slices/Components/MorfeoComponent.ts
index 41ce54a1..25f39843 100644
--- a/devtool/src/_shared/components/Slices/Components/MorfeoComponent.ts
+++ b/devtool/src/_shared/components/Slices/Components/MorfeoComponent.ts
@@ -5,6 +5,7 @@ import clsx from 'clsx';
type Props = {
name: Component;
variant?: string;
+ applyDefaultStyle?: boolean;
};
type TagName = keyof HTMLElementTagNameMap;
@@ -13,12 +14,18 @@ export const MorfeoComponent: React.FC = ({
name,
variant,
children,
+ applyDefaultStyle,
...props
}) => {
- const { tag = 'div', props: componentProps = {} } =
- component(name, variant).get() || {};
+ const {
+ tag = 'div',
+ props: componentProps = {},
+ meta,
+ } = component(name, variant).get() || {};
+ const { devtoolConfig } = meta || {};
const { classes } = getStyles({
[name]: {
+ ...(applyDefaultStyle && devtoolConfig?.style),
componentName: name as Component,
variant,
},
@@ -37,6 +44,6 @@ export const MorfeoComponent: React.FC = ({
...(props as any).style,
...(componentProps as any).style,
},
- children,
+ children: devtoolConfig?.label || children,
});
};
diff --git a/devtool/src/_shared/components/Slices/Components/Preview.tsx b/devtool/src/_shared/components/Slices/Components/Preview.tsx
index 3ffc993b..d8d8b2c3 100644
--- a/devtool/src/_shared/components/Slices/Components/Preview.tsx
+++ b/devtool/src/_shared/components/Slices/Components/Preview.tsx
@@ -1,5 +1,5 @@
-import React, { useCallback } from 'react';
-import { Component, component } from '@morfeo/react';
+import React, { useCallback, useMemo} from 'react';
+import { Color, Component, component, morfeo } from '@morfeo/react';
import { useRouter } from '../../../hooks/useRouter';
import { RouteName } from '../../../contexts';
import { SliceName } from '../../../contexts/Routing/types';
@@ -41,7 +41,10 @@ const Info: React.FC = ({ name, variant }) => {
export const Preview: React.FC = ({ name, variant }) => {
const { navigate } = useRouter();
-
+ const { meta } =
+ component(name, variant).get() || {};
+ const currentThemeName = morfeo.getCurrent();
+ const { devtoolConfig } = meta || {};
const onClick = useCallback(() => {
navigate(RouteName.COMPONENT, {
slice: SliceName.COMPONENTS,
@@ -50,6 +53,13 @@ export const Preview: React.FC = ({ name, variant }) => {
});
}, [name, variant, navigate]);
+ const computedBackground = useMemo(() => {
+ if (typeof devtoolConfig?.background === 'object') {
+ return devtoolConfig?.background[currentThemeName]
+ }
+ return (devtoolConfig?.background as Color) || '#fff' as Color
+ }, [currentThemeName, devtoolConfig?.background])
+
return (
= ({ name, variant }) => {
kind="squared"
className={styles.previewContainer}
copyText={variant || name}
+ style={{
+ bg: computedBackground,
+ }}
>
-
+
{name}
diff --git a/devtool/src/_shared/css/dark-components.css b/devtool/src/_shared/css/dark-components.css
index ac3058b3..50cfb33c 100644
--- a/devtool/src/_shared/css/dark-components.css
+++ b/devtool/src/_shared/css/dark-components.css
@@ -159,23 +159,18 @@
line-height: var(--line-heights-heading);
}
[data-morfeo-theme="dark"] .morfeo-typography-p1 {
- font-size: var(--font-sizes-m);
+ 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-p2 {
- font-size: var(--font-sizes-s);
+ font-size: var(--font-sizes-xs);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
letter-spacing: var(--letter-spacings-body);
}
[data-morfeo-theme="dark"] .morfeo-typography-p3 {
- font-size: var(--font-sizes-xs);
- font-family: var(--fonts-regular);
- line-height: var(--line-heights-body);
-}
-[data-morfeo-theme="dark"] .morfeo-typography-p4 {
font-size: var(--font-sizes-xxs);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
diff --git a/devtool/src/_shared/css/light-components.css b/devtool/src/_shared/css/light-components.css
index c1816846..ecfdc674 100644
--- a/devtool/src/_shared/css/light-components.css
+++ b/devtool/src/_shared/css/light-components.css
@@ -159,23 +159,18 @@
line-height: var(--line-heights-heading);
}
[data-morfeo-theme="light"] .morfeo-typography-p1 {
- font-size: var(--font-sizes-m);
+ 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="light"] .morfeo-typography-p2 {
- font-size: var(--font-sizes-s);
+ font-size: var(--font-sizes-xs);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
letter-spacing: var(--letter-spacings-body);
}
[data-morfeo-theme="light"] .morfeo-typography-p3 {
- font-size: var(--font-sizes-xs);
- font-family: var(--fonts-regular);
- line-height: var(--line-heights-body);
-}
-[data-morfeo-theme="light"] .morfeo-typography-p4 {
font-size: var(--font-sizes-xxs);
font-family: var(--fonts-regular);
line-height: var(--line-heights-body);
diff --git a/devtool/src/_shared/styles/components/typography.ts b/devtool/src/_shared/styles/components/typography.ts
index ffa24d5f..ea66d899 100644
--- a/devtool/src/_shared/styles/components/typography.ts
+++ b/devtool/src/_shared/styles/components/typography.ts
@@ -57,7 +57,7 @@ export const Typography: ComponentConfig = {
p1: {
tag: 'p',
style: {
- fontSize: 'm',
+ fontSize: 's',
letterSpacing: 'body',
lineHeight: 'body',
},
@@ -65,19 +65,12 @@ export const Typography: ComponentConfig = {
p2: {
tag: 'p',
style: {
- fontSize: 's',
+ fontSize: 'xs',
letterSpacing: 'body',
lineHeight: 'body',
},
},
p3: {
- tag: 'p',
- style: {
- fontSize: 'xs',
- lineHeight: 'body',
- },
- },
- p4: {
tag: 'p',
style: {
fontSize: 'xxs',
diff --git a/devtool/src/devtool/pages/Home/SliceCard.tsx b/devtool/src/devtool/pages/Home/SliceCard.tsx
index 6b796fac..ef00a56f 100644
--- a/devtool/src/devtool/pages/Home/SliceCard.tsx
+++ b/devtool/src/devtool/pages/Home/SliceCard.tsx
@@ -37,7 +37,7 @@ export const SliceCard: React.FC = ({ name, values, status }) => {
return undefined;
}
return (
- {values}
+ {values}
);
}, [isComingSoon, values]);
@@ -56,12 +56,12 @@ export const SliceCard: React.FC = ({ name, values, status }) => {
return (
- {labelText}
+ {labelText.toUpperCase()}
);
}, [isEmpty, labelText]);
diff --git a/devtool/src/devtool/pages/Home/style.module.css b/devtool/src/devtool/pages/Home/style.module.css
index acaceb7f..30e7f365 100644
--- a/devtool/src/devtool/pages/Home/style.module.css
+++ b/devtool/src/devtool/pages/Home/style.module.css
@@ -56,15 +56,17 @@
position: absolute;
margin-left: var(--spacings-xxs);
margin-right: var(--spacings-xxs);
- transition: var(--transitions-medium);
+ transition: var(--transitions-none);
}
.valuesContainer:hover, .valuesContainer.comingSoon {
width: fit-content;
+ transition: var(--transitions-medium);
}
.sliceContainer:hover .valueLabel, .valuesContainer.comingSoon .valueLabel {
max-width: 10rem;
opacity: 1;
position: relative;
+ transition: var(--transitions-medium);
}
\ No newline at end of file
diff --git a/docs/docs/Features/web-extension.mdx b/docs/docs/Features/web-extension.mdx
index 74256297..bae0d935 100644
--- a/docs/docs/Features/web-extension.mdx
+++ b/docs/docs/Features/web-extension.mdx
@@ -54,6 +54,54 @@ enableMorfeoDevTool();
morfeo.setTheme('light', myTheme);
```
+## Components customization
+
+:::caution Use it with caution!
+This feature is very helpful to present your components in a nice way but it will change the real component style.
+So, use it consciously.
+:::
+
+Sometimes the style of a component couldn't be enough consistent to present it in a nice way inside the web extension.
+
+```typescript
+const Flex = {
+ tag: 'div',
+ style: {
+ display: 'flex'
+ }
+}
+```
+
+In this case it could be needed to add an additional style, in order to present the component in a better way. You can use the `devtoolConfig` property inside `meta` to define these additional behaviors.
+
+```typescript
+const Flex = {
+ tag: 'div',
+ style: {
+ display: 'flex'
+ },
+ meta: {
+ devtoolConfig: {
+ label: 'Flex Div',
+ style: {
+ size: '100px',
+ bg: 'gray.light'
+ },
+ background: 'white',
+ }
+ }
+}
+```
+
+### devtoolConfig Props
+
+| prop | description | type |
+|-------|-------------|--------|
+| label | the text used as component children in the web extension | `string` |
+| style | the default style of the component in the web extension | `Style` |
+| background | the default background for the card that contains the component | `Color` `Record` (where the string is the theme name) |
+
+
## Contribute
We want to improve the web extension as much as possible and add functionalities, If you want to help us, check our [GitHub](https://github.com/VLK-STUDIO/morfeo)!
diff --git a/docs/src/styles/components/box.ts b/docs/src/styles/components/box.ts
new file mode 100644
index 00000000..b70f9bec
--- /dev/null
+++ b/docs/src/styles/components/box.ts
@@ -0,0 +1,35 @@
+import { ComponentConfig } from '@morfeo/react';
+
+export const Box: ComponentConfig = {
+ tag: 'div',
+ style: {
+ fontFamily: 'regular'
+ },
+ variants: {
+ flexRow: {
+ style: {
+ display: 'flex',
+ flexDirection: 'row'
+ }
+ },
+ flexColumn: {
+ style: {
+ flexDirection: 'column'
+ }
+ }
+ },
+ meta: {
+ description: 'a simple div',
+ devtoolConfig: {
+ background: 'background',
+ style: {
+ width: '80px',
+ height: '80px',
+ backgroundColor: 'gray.lighter',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ }
+ }
+ }
+} as ComponentConfig;
diff --git a/docs/src/styles/components/button.ts b/docs/src/styles/components/button.ts
index ceb96298..837daf0a 100644
--- a/docs/src/styles/components/button.ts
+++ b/docs/src/styles/components/button.ts
@@ -19,18 +19,35 @@ export const Button: ComponentConfig = {
},
},
variants: {
- round: {
+ inverted: {
style: {
- corner: 'round',
- px: 'none',
- py: 'none',
- size: 'xxl',
+ bg: 'transparent',
+ border: 'primary',
+ borderColor: 'primary',
+ color: 'textColor',
+ },
+ },
+ disabled: {
+ style: {
+ bg: 'grey.light',
+ color: 'light',
+ pointerEvent: 'none',
+ cursor: 'default',
+ '&:hover': {
+ opacity: 1
+ }
},
},
error: {
style: {
- bg: 'gray.lightest',
- color: 'error',
+ bg: 'error',
+ color: 'white',
+ },
+ },
+ warning: {
+ style: {
+ bg: 'warning',
+ color: 'white',
},
},
success: {
@@ -38,9 +55,42 @@ export const Button: ComponentConfig = {
bg: 'success',
},
},
+ round: {
+ style: {
+ corner: 'round',
+ px: 'none',
+ py: 'none',
+ size: 'xxl',
+ },
+ meta: {
+ devtoolConfig: {
+ label: 'B',
+ },
+ },
+ },
+ 'round.inverted': {
+ style: {
+ bg: 'transparent',
+ border: 'primary',
+ borderColor: 'primary',
+ color: 'textColor',
+ corner: 'round',
+ px: 'none',
+ py: 'none',
+ size: 'xxl',
+ },
+ meta: {
+ devtoolConfig: {
+ label: 'B',
+ },
+ },
+ },
},
meta: {
tags: ['ui', 'form'],
description: 'Button component',
+ devtoolConfig: {
+ background: 'background',
+ },
},
} as ComponentConfig;
diff --git a/docs/src/styles/components/card.ts b/docs/src/styles/components/card.ts
index 09a34303..3da33811 100644
--- a/docs/src/styles/components/card.ts
+++ b/docs/src/styles/components/card.ts
@@ -9,6 +9,9 @@ export const Card: ComponentConfig = {
display: 'flex',
alignItems: 'center',
flexDirection: 'column',
+ fontFamily: 'regular',
+ bg: 'background',
+ shadow: 'light',
},
variants: {
primary: {
@@ -30,5 +33,15 @@ export const Card: ComponentConfig = {
meta: {
tags: ['container', 'ui'],
description: 'Card component',
+ devtoolConfig: {
+ background: 'background',
+ style: {
+ width: '80px',
+ height: '80px',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ }
+ }
},
} as ComponentConfig;
diff --git a/docs/src/styles/components/index.ts b/docs/src/styles/components/index.ts
index 46a9a41e..83a5f1f4 100644
--- a/docs/src/styles/components/index.ts
+++ b/docs/src/styles/components/index.ts
@@ -1,9 +1,10 @@
import { Button } from './button';
import { Typography } from './typography';
import { Card } from './card';
+import { Box } from './box';
export const components = {
- Box: { style: {}, variants: {} },
+ Box,
Card,
Button,
Typography,
diff --git a/docs/src/styles/components/typography.ts b/docs/src/styles/components/typography.ts
index e15995b1..21e846a0 100644
--- a/docs/src/styles/components/typography.ts
+++ b/docs/src/styles/components/typography.ts
@@ -100,5 +100,8 @@ export const Typography: ComponentConfig = {
meta: {
description: 'Typography component used to render text',
tags: ['typography', 'fonts'],
+ devtoolConfig: {
+ background: 'background'
+ }
},
} as ComponentConfig;
diff --git a/packages/spec/src/types/components.ts b/packages/spec/src/types/components.ts
index 3e9248f8..6e070310 100644
--- a/packages/spec/src/types/components.ts
+++ b/packages/spec/src/types/components.ts
@@ -1,8 +1,15 @@
import { Style } from './style';
+import { Color } from './colors';
export interface ComponentMeta {
description?: string;
tags?: string[];
+ devtoolConfig?: {
+ style?: Style;
+ background?: Color | Record;
+ label?: string;
+ hide?: boolean;
+ }
}
type ComponentStyle = {