@streamlinedfi/div 0.1.0 → 0.1.1

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 CHANGED
@@ -1,2 +1,136 @@
1
- # div
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.0",
3
+ "version": "0.1.1",
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": {
package/src/Text.js ADDED
@@ -0,0 +1,58 @@
1
+ import isFunction from 'lodash/isFunction';
2
+ import styled from 'styled-components';
3
+ import { colorMixin, sizeFormatter } from './utils';
4
+
5
+ import { divMixin, renderCss } from './Div';
6
+
7
+ const textRules = {
8
+ weight: 'font-weight',
9
+ size: {
10
+ css: 'font-size',
11
+ format: sizeFormatter,
12
+ },
13
+ color: {
14
+ css: (props, media, extensions) => {
15
+ const color = extensions.includes('hover')
16
+ ? props.$color$hover
17
+ : props.$color;
18
+
19
+ return colorMixin(color, props.theme);
20
+ },
21
+ },
22
+ tnum: 'font-feature-settings: "tnum";letter-spacing:-0.04em;',
23
+ breakWord: 'word-break: break-word;',
24
+ noBreak: 'white-space: nowrap;',
25
+ uppercase: 'text-transform: uppercase;',
26
+ serif: 'font-family: "Times New Roman", Times, serif',
27
+ 'spacing|letterSpacing': `letter-spacing`,
28
+ left: 'text-align: left;',
29
+ right: 'text-align: right;',
30
+ center: 'text-align: center;',
31
+ lineThrough: 'text-decoration: line-through',
32
+ // underline: 'text-decoration: underline;',
33
+ linearGradient: props => `
34
+ -webkit-text-fill-color: transparent;
35
+ text-fill-color: transparent;
36
+ -webkit-background-clip: text;
37
+ background-clip: text;
38
+ background-image: linear-gradient(${
39
+ isFunction(props.$linearGradient)
40
+ ? props.$linearGradient(props.theme)
41
+ : props.$linearGradient
42
+ });
43
+ `,
44
+ ellipsis: `
45
+ white-space: nowrap;
46
+ overflow: hidden;
47
+ text-overflow: ellipsis;
48
+ max-width: 100%;
49
+ `,
50
+ underline: 'text-decoration: underline;',
51
+ };
52
+
53
+ const Text = styled.p`
54
+ ${props => divMixin(props)}
55
+ ${props => renderCss(props, textRules)}
56
+ `;
57
+
58
+ export default Text;
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import Div from './Div';
1
+ import Div, { divMixin } from './Div';
2
+ import Text from './Text';
2
3
  import createUISystem from './createUISystem';
3
4
 
4
5
  export default Div;
5
6
 
6
- export { createUISystem };
7
+ export { createUISystem, Div, divMixin, Text };
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
+ };
@@ -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
- <StrictMode>
9
- <ThemeProvider theme={uiSystem.theme}>
10
- <App />
11
- </ThemeProvider>
12
- </StrictMode>,
7
+ <ThemeProvider theme={uiSystem.theme}>
8
+ <App />
9
+ </ThemeProvider>,
13
10
  );