@streamlinedfi/div 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -1
- package/package.json +20 -3
- package/src/Text.js +57 -0
- package/src/index.js +3 -2
- package/src/utils.js +24 -0
- package/test-app/src/main.jsx +3 -6
- package/tsup.config.js +21 -0
package/README.md
CHANGED
|
@@ -1,2 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Build UI with Speed
|
|
2
|
+
|
|
2
3
|
Streamlined Div is a styled-components extension of the html div for building products with speed
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
# with Yarn
|
|
9
|
+
$ yarn add @streamlinedfi/div styled-components
|
|
10
|
+
|
|
11
|
+
# with npm
|
|
12
|
+
$ npm i @streamlinedfi/div styled-components
|
|
13
|
+
|
|
14
|
+
# with pnpm
|
|
15
|
+
$ pnpm add @streamlinedfi/div styled-components
|
|
16
|
+
|
|
17
|
+
# with Bun
|
|
18
|
+
$ bun add @streamlinedfi/div styled-components
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### 1. Create a UI System
|
|
24
|
+
|
|
25
|
+
```jsx
|
|
26
|
+
import { createUISystem } from '@streamlinedfi/div';
|
|
27
|
+
|
|
28
|
+
export const uiSystem = createUISystem({
|
|
29
|
+
theme: {
|
|
30
|
+
background: 'darkblue',
|
|
31
|
+
red: 'red',
|
|
32
|
+
blue: 'blue',
|
|
33
|
+
green: 'green',
|
|
34
|
+
},
|
|
35
|
+
breakpoints: {
|
|
36
|
+
mobile: { max: 768 },
|
|
37
|
+
tablet: { min: 769, max: 1023 },
|
|
38
|
+
desktop: { min: 1024 },
|
|
39
|
+
},
|
|
40
|
+
spacingUnit: 16,
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Wrap app with uiSystem.theme
|
|
45
|
+
|
|
46
|
+
```jsx
|
|
47
|
+
import { createRoot } from 'react-dom/client';
|
|
48
|
+
import { ThemeProvider } from 'styled-components';
|
|
49
|
+
import App from './App.jsx';
|
|
50
|
+
import { uiSystem } from './uiSystem';
|
|
51
|
+
|
|
52
|
+
createRoot(document.getElementById('root')).render(
|
|
53
|
+
<ThemeProvider theme={uiSystem.theme}>
|
|
54
|
+
<App />
|
|
55
|
+
</ThemeProvider>,
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Use @streamlinedfi/div
|
|
60
|
+
|
|
61
|
+
```jsx
|
|
62
|
+
import Div from '@streamlinedfi/div';
|
|
63
|
+
|
|
64
|
+
function App() {
|
|
65
|
+
return (
|
|
66
|
+
<Div
|
|
67
|
+
as="main"
|
|
68
|
+
$flex
|
|
69
|
+
$innerCenter
|
|
70
|
+
$grow
|
|
71
|
+
$p={2.5}
|
|
72
|
+
$background={theme => theme.background}
|
|
73
|
+
>
|
|
74
|
+
<Div $w={100} $h={100} />
|
|
75
|
+
<Div $w={100} $h={100} />
|
|
76
|
+
</Div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default App;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Shorthand props
|
|
84
|
+
|
|
85
|
+
It inherits most of css rules:
|
|
86
|
+
|
|
87
|
+
| CSS Property | Shorthand Prop |
|
|
88
|
+
| ---------------- | ----------------- |
|
|
89
|
+
| max-width | \$maxWidth |
|
|
90
|
+
| background-color | \$backgroundColor |
|
|
91
|
+
| text-decoration | \$textDecoration |
|
|
92
|
+
|
|
93
|
+
But also has some shorthands ([see the full list in `src/rules.js`](./src/rules.js)):
|
|
94
|
+
|
|
95
|
+
| CSS Property | Shorthand Prop |
|
|
96
|
+
| ------------- | -------------- |
|
|
97
|
+
| width | \$w |
|
|
98
|
+
| height | \$h |
|
|
99
|
+
| padding | \$p |
|
|
100
|
+
| padding-top | \$pt |
|
|
101
|
+
| ... | ... |
|
|
102
|
+
| margin | \$mt |
|
|
103
|
+
| margin-bottom | \$mb |
|
|
104
|
+
| ... | ... |
|
|
105
|
+
|
|
106
|
+
And some props are new extensions (handy for flex):
|
|
107
|
+
|
|
108
|
+
| New Shorthand Prop |
|
|
109
|
+
| ------------------ |
|
|
110
|
+
| \$innerCenter |
|
|
111
|
+
| \$outerCenter |
|
|
112
|
+
| \$innerTop |
|
|
113
|
+
| \$innerLeft |
|
|
114
|
+
| ... |
|
|
115
|
+
|
|
116
|
+
And some props use the spacing system based on the provided spacingUnit.
|
|
117
|
+
|
|
118
|
+
```jsx
|
|
119
|
+
const uiSystem = createUISystem({
|
|
120
|
+
// ...
|
|
121
|
+
spacingUnit: 16,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* with spacingUnit: 16, the div will have:
|
|
126
|
+
* padding-left: 32px
|
|
127
|
+
* margin-bottom: 16px;
|
|
128
|
+
*/
|
|
129
|
+
<Div $pl={2} $mb={1}>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Lastly, the div accepts media props:
|
|
133
|
+
|
|
134
|
+
```jsx
|
|
135
|
+
<Div $w={300} $mobile$w={100} $tablet$w={200}>
|
|
136
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlinedfi/div",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Streamlined Div is a styled-components extension of the html div for building products with speed",
|
|
5
5
|
"author": "Streamlined Finance",
|
|
6
6
|
"repository": {
|
|
@@ -12,11 +12,28 @@
|
|
|
12
12
|
"url": "https://github.com/streamlinedfi/div/issues"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/streamlinedfi/div#readme",
|
|
15
|
-
"
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.mjs",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
16
24
|
"scripts": {
|
|
17
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"analyze": "npx esbuild-visualizer --metadata ./dist/metafile-esm.json"
|
|
18
29
|
},
|
|
19
30
|
"peerDependencies": {
|
|
31
|
+
"react": "^19.2.0",
|
|
32
|
+
"react-dom": "^19.2.0",
|
|
20
33
|
"styled-components": "^6.1.19"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsup": "^8.5.0",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
21
38
|
}
|
|
22
39
|
}
|
package/src/Text.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { colorMixin, sizeFormatter } from './utils';
|
|
3
|
+
|
|
4
|
+
import { divMixin, renderCss } from './Div';
|
|
5
|
+
|
|
6
|
+
const textRules = {
|
|
7
|
+
weight: 'font-weight',
|
|
8
|
+
size: {
|
|
9
|
+
css: 'font-size',
|
|
10
|
+
format: sizeFormatter,
|
|
11
|
+
},
|
|
12
|
+
color: {
|
|
13
|
+
css: (props, media, extensions) => {
|
|
14
|
+
const color = extensions.includes('hover')
|
|
15
|
+
? props.$color$hover
|
|
16
|
+
: props.$color;
|
|
17
|
+
|
|
18
|
+
return colorMixin(color, props.theme);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
tnum: 'font-feature-settings: "tnum";letter-spacing:-0.04em;',
|
|
22
|
+
breakWord: 'word-break: break-word;',
|
|
23
|
+
noBreak: 'white-space: nowrap;',
|
|
24
|
+
uppercase: 'text-transform: uppercase;',
|
|
25
|
+
serif: 'font-family: "Times New Roman", Times, serif',
|
|
26
|
+
'spacing|letterSpacing': `letter-spacing`,
|
|
27
|
+
left: 'text-align: left;',
|
|
28
|
+
right: 'text-align: right;',
|
|
29
|
+
center: 'text-align: center;',
|
|
30
|
+
lineThrough: 'text-decoration: line-through',
|
|
31
|
+
// underline: 'text-decoration: underline;',
|
|
32
|
+
linearGradient: props => `
|
|
33
|
+
-webkit-text-fill-color: transparent;
|
|
34
|
+
text-fill-color: transparent;
|
|
35
|
+
-webkit-background-clip: text;
|
|
36
|
+
background-clip: text;
|
|
37
|
+
background-image: linear-gradient(${
|
|
38
|
+
typeof props.$linearGradient === 'function'
|
|
39
|
+
? props.$linearGradient(props.theme)
|
|
40
|
+
: props.$linearGradient
|
|
41
|
+
});
|
|
42
|
+
`,
|
|
43
|
+
ellipsis: `
|
|
44
|
+
white-space: nowrap;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
text-overflow: ellipsis;
|
|
47
|
+
max-width: 100%;
|
|
48
|
+
`,
|
|
49
|
+
underline: 'text-decoration: underline;',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const Text = styled.p`
|
|
53
|
+
${props => divMixin(props)}
|
|
54
|
+
${props => renderCss(props, textRules)}
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
export default Text;
|
package/src/index.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -81,3 +81,27 @@ export function getMediaPropRegex(theme) {
|
|
|
81
81
|
|
|
82
82
|
return mediaPropRegex;
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
export function colorMixin(color, theme) {
|
|
86
|
+
if (color) {
|
|
87
|
+
if ([100, 200, 300, 400, 500, 600, 700, 800, 900].includes(color)) {
|
|
88
|
+
return `color: ${theme[`fill${color}`]};`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (typeof color === 'string') {
|
|
92
|
+
if (theme[color]) {
|
|
93
|
+
return `color: ${theme[color]};`;
|
|
94
|
+
}
|
|
95
|
+
return `color: ${color};`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const sizeFormatter = value => {
|
|
103
|
+
if (typeof value === 'number') {
|
|
104
|
+
return `${value}px`;
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
};
|
package/test-app/src/main.jsx
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { StrictMode } from 'react';
|
|
2
1
|
import { createRoot } from 'react-dom/client';
|
|
3
2
|
import { ThemeProvider } from 'styled-components';
|
|
4
3
|
import App from './App.jsx';
|
|
5
4
|
import { uiSystem } from './uiSystem.js';
|
|
6
5
|
|
|
7
6
|
createRoot(document.getElementById('root')).render(
|
|
8
|
-
<
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
</ThemeProvider>
|
|
12
|
-
</StrictMode>,
|
|
7
|
+
<ThemeProvider theme={uiSystem.theme}>
|
|
8
|
+
<App />
|
|
9
|
+
</ThemeProvider>,
|
|
13
10
|
);
|
package/tsup.config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ['src/index.js'],
|
|
5
|
+
format: ['cjs', 'esm'],
|
|
6
|
+
dts: false,
|
|
7
|
+
splitting: true,
|
|
8
|
+
sourcemap: true,
|
|
9
|
+
clean: true,
|
|
10
|
+
minify: true,
|
|
11
|
+
metafile: true,
|
|
12
|
+
target: 'es2020',
|
|
13
|
+
outDir: 'dist',
|
|
14
|
+
external: ['react', 'react-dom', 'styled-components'],
|
|
15
|
+
loader: {
|
|
16
|
+
'.js': 'jsx',
|
|
17
|
+
},
|
|
18
|
+
outExtension({ format }) {
|
|
19
|
+
return { js: format === 'esm' ? '.mjs' : '.cjs' };
|
|
20
|
+
},
|
|
21
|
+
});
|