-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: UIMix elements as React components (#194)
- Loading branch information
1 parent
4753ebb
commit ab76991
Showing
20 changed files
with
1,223 additions
and
56 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"sourceType": "unambiguous", | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"chrome": 100 | ||
} | ||
} | ||
], | ||
"@babel/preset-typescript", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [] | ||
} |
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,17 @@ | ||
import type { StorybookConfig } from "@storybook/react-webpack5"; | ||
const config: StorybookConfig = { | ||
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-interactions", | ||
], | ||
framework: { | ||
name: "@storybook/react-webpack5", | ||
options: {}, | ||
}, | ||
docs: { | ||
autodocs: "tag", | ||
}, | ||
}; | ||
export default config; |
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,15 @@ | ||
import type { Preview } from "@storybook/react"; | ||
|
||
const preview: Preview = { | ||
parameters: { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default preview; |
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,33 @@ | ||
{ | ||
"name": "@uimix/elements-react", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"lint": "eslint src", | ||
"storybook": "storybook dev -p 8008", | ||
"build-storybook": "storybook build" | ||
}, | ||
"dependencies": { | ||
"csstype": "^3.1.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.21.4", | ||
"@babel/preset-react": "^7.18.6", | ||
"@babel/preset-typescript": "^7.21.4", | ||
"@storybook/addon-essentials": "^7.0.7", | ||
"@storybook/addon-interactions": "^7.0.7", | ||
"@storybook/addon-links": "^7.0.7", | ||
"@storybook/blocks": "^7.0.7", | ||
"@storybook/react": "^7.0.7", | ||
"@storybook/react-webpack5": "^7.0.7", | ||
"@storybook/testing-library": "^0.0.14-next.2", | ||
"@types/react": "^18.0.38", | ||
"@types/react-dom": "^18.0.11", | ||
"prop-types": "^15.8.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"storybook": "^7.0.7", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
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,29 @@ | ||
import { Box, Text } from "./Box"; | ||
|
||
export default { | ||
title: "Box", | ||
component: Box, | ||
}; | ||
|
||
export const Basic = () => { | ||
return <Box width={100} height={200} fills={[{ solid: "#c0ffee" }]} />; | ||
}; | ||
|
||
export const WithText = () => { | ||
return ( | ||
<Box | ||
width={100} | ||
height={200} | ||
fills={[{ solid: "#c0ffee" }]} | ||
layout="flex" | ||
flexDirection="y" | ||
rowGap={20} | ||
paddingLeft={10} | ||
paddingRight={10} | ||
> | ||
<Box width={100} height={100} fills={[{ solid: "#f0f0f0" }]} /> | ||
<Text fills={[{ solid: "#000" }]} textContent="Hello, world!" /> | ||
<Text fills={[{ solid: "#666" }]} textContent="This is a text" /> | ||
</Box> | ||
); | ||
}; |
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,73 @@ | ||
import { ReactNode, useId } from "react"; | ||
import { | ||
StyleProps, | ||
defaultStyle, | ||
SelfAndChildrenCSS, | ||
buildNodeCSS, | ||
} from "../style"; | ||
|
||
function kebabCase(str: string): string { | ||
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`); | ||
} | ||
|
||
export const Box: React.FC< | ||
Partial<StyleProps> & { | ||
children?: ReactNode; | ||
} | ||
> = (props) => { | ||
const styles = buildNodeCSS("frame", { | ||
...defaultStyle, | ||
...props, | ||
}); | ||
|
||
const id = useId().replaceAll(":", "_"); | ||
const className = `box-${id}`; | ||
|
||
return ( | ||
<div className={className}> | ||
<Style targetClassName={className} styles={styles} /> | ||
{props.children} | ||
</div> | ||
); | ||
}; | ||
|
||
export const Text: React.FC< | ||
Partial<StyleProps> & { | ||
children?: ReactNode; | ||
} | ||
> = (props) => { | ||
const styles = buildNodeCSS("text", { | ||
...defaultStyle, | ||
...props, | ||
}); | ||
|
||
const id = useId().replaceAll(":", "_"); | ||
const className = `box-${id}`; | ||
|
||
return ( | ||
<div className={className}> | ||
<Style targetClassName={className} styles={styles} /> | ||
{props.textContent} | ||
</div> | ||
); | ||
}; | ||
|
||
const Style: React.FC<{ | ||
targetClassName: string; | ||
styles: SelfAndChildrenCSS; | ||
}> = ({ styles, targetClassName }) => { | ||
const cssBody = Object.entries(styles.self) | ||
.map(([key, value]) => { | ||
return `${kebabCase(key)}: ${String(value)};`; | ||
}) | ||
.join(";"); | ||
const childrenCSSBody = Object.entries(styles.children) | ||
.map(([key, value]) => { | ||
return `${kebabCase(key)}: ${String(value)};`; | ||
}) | ||
.join(";"); | ||
|
||
const styleText = `.${targetClassName}{${cssBody}} .${targetClassName}>*{${childrenCSSBody}}`; | ||
|
||
return <style>{styleText}</style>; | ||
}; |
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 @@ | ||
export * from "./Box"; |
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,2 @@ | ||
export * from "./components"; | ||
export * from "./style"; |
Oops, something went wrong.
ab76991
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
uimix-editor – ./packages/editor
uimix-editor.vercel.app
uimix-editor-git-main-macaron-elements.vercel.app
*.editor.uimix.app
uimix-editor-macaron-elements.vercel.app
ab76991
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
uimix-dashboard – ./packages/dashboard
uimix-dashboard-macaron-elements.vercel.app
uimix-dashboard.vercel.app
uimix-dashboard-git-main-macaron-elements.vercel.app
www.uimix.app
uimix.app