@mirai/ui 1.0.0
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 +349 -0
- package/build/components/Button/Button.js +44 -0
- package/build/components/Button/Button.js.map +1 -0
- package/build/components/Button/Button.module.css +79 -0
- package/build/components/Button/__tests__/__snapshots__/Button.test.js.snap +113 -0
- package/build/components/Button/index.js +19 -0
- package/build/components/Button/index.js.map +1 -0
- package/build/components/Calendar/Calendar.Month.js +101 -0
- package/build/components/Calendar/Calendar.Month.js.map +1 -0
- package/build/components/Calendar/Calendar.Week.js +144 -0
- package/build/components/Calendar/Calendar.Week.js.map +1 -0
- package/build/components/Calendar/Calendar.constants.js +11 -0
- package/build/components/Calendar/Calendar.constants.js.map +1 -0
- package/build/components/Calendar/Calendar.js +146 -0
- package/build/components/Calendar/Calendar.js.map +1 -0
- package/build/components/Calendar/Calendar.module.css +96 -0
- package/build/components/Calendar/__tests__/__snapshots__/Calendar.test.jsx.snap +17853 -0
- package/build/components/Calendar/helpers/getFirstDateOfMonth.js +16 -0
- package/build/components/Calendar/helpers/getFirstDateOfMonth.js.map +1 -0
- package/build/components/Calendar/helpers/getFirstDateOfWeek.js +20 -0
- package/build/components/Calendar/helpers/getFirstDateOfWeek.js.map +1 -0
- package/build/components/Calendar/helpers/getHeader.js +23 -0
- package/build/components/Calendar/helpers/getHeader.js.map +1 -0
- package/build/components/Calendar/helpers/getToday.js +15 -0
- package/build/components/Calendar/helpers/getToday.js.map +1 -0
- package/build/components/Calendar/helpers/getWeekNumber.js +17 -0
- package/build/components/Calendar/helpers/getWeekNumber.js.map +1 -0
- package/build/components/Calendar/helpers/getWeekdays.js +27 -0
- package/build/components/Calendar/helpers/getWeekdays.js.map +1 -0
- package/build/components/Calendar/helpers/index.js +97 -0
- package/build/components/Calendar/helpers/index.js.map +1 -0
- package/build/components/Calendar/helpers/isJest.js +9 -0
- package/build/components/Calendar/helpers/isJest.js.map +1 -0
- package/build/components/Calendar/index.js +19 -0
- package/build/components/Calendar/index.js.map +1 -0
- package/build/components/Form/Form.js +184 -0
- package/build/components/Form/Form.js.map +1 -0
- package/build/components/Form/__tests__/__snapshots__/Form.test.jsx.snap +47 -0
- package/build/components/Form/helpers/getChildrenErrors.js +47 -0
- package/build/components/Form/helpers/getChildrenErrors.js.map +1 -0
- package/build/components/Form/helpers/getChildrenValues.js +46 -0
- package/build/components/Form/helpers/getChildrenValues.js.map +1 -0
- package/build/components/Form/helpers/getField.js +17 -0
- package/build/components/Form/helpers/getField.js.map +1 -0
- package/build/components/Form/helpers/groupState.js +29 -0
- package/build/components/Form/helpers/groupState.js.map +1 -0
- package/build/components/Form/helpers/index.js +58 -0
- package/build/components/Form/helpers/index.js.map +1 -0
- package/build/components/Form/index.js +19 -0
- package/build/components/Form/index.js.map +1 -0
- package/build/components/InputNumber/InputNumber.js +71 -0
- package/build/components/InputNumber/InputNumber.js.map +1 -0
- package/build/components/InputNumber/InputNumber.module.css +13 -0
- package/build/components/InputNumber/__tests__/__snapshots__/InputNumber.test.js.snap +616 -0
- package/build/components/InputNumber/index.js +19 -0
- package/build/components/InputNumber/index.js.map +1 -0
- package/build/components/InputText/InputText.js +100 -0
- package/build/components/InputText/InputText.js.map +1 -0
- package/build/components/InputText/InputText.module.css +68 -0
- package/build/components/InputText/__tests__/__snapshots__/InputText.test.js.snap +212 -0
- package/build/components/InputText/index.js +19 -0
- package/build/components/InputText/index.js.map +1 -0
- package/build/components/Modal/Modal.js +50 -0
- package/build/components/Modal/Modal.js.map +1 -0
- package/build/components/Modal/Modal.module.css +70 -0
- package/build/components/Modal/__tests__/__snapshots__/Modal.test.js.snap +150 -0
- package/build/components/Modal/index.js +19 -0
- package/build/components/Modal/index.js.map +1 -0
- package/build/components/index.js +84 -0
- package/build/components/index.js.map +1 -0
- package/build/helpers/getInputErrors.js +45 -0
- package/build/helpers/getInputErrors.js.map +1 -0
- package/build/helpers/index.js +32 -0
- package/build/helpers/index.js.map +1 -0
- package/build/helpers/isValidDate.js +58 -0
- package/build/helpers/isValidDate.js.map +1 -0
- package/build/helpers/isValidEmail.js +15 -0
- package/build/helpers/isValidEmail.js.map +1 -0
- package/build/helpers/isValidPhone.js +25 -0
- package/build/helpers/isValidPhone.js.map +1 -0
- package/build/helpers/styles.js +21 -0
- package/build/helpers/styles.js.map +1 -0
- package/build/hooks/helpers/getNavigator.js +33 -0
- package/build/hooks/helpers/getNavigator.js.map +1 -0
- package/build/hooks/helpers/getResolution.js +22 -0
- package/build/hooks/helpers/getResolution.js.map +1 -0
- package/build/hooks/helpers/index.js +32 -0
- package/build/hooks/helpers/index.js.map +1 -0
- package/build/hooks/index.js +19 -0
- package/build/hooks/index.js.map +1 -0
- package/build/hooks/useDevice.js +48 -0
- package/build/hooks/useDevice.js.map +1 -0
- package/build/index.js +71 -0
- package/build/index.js.map +1 -0
- package/build/primitives/Icon/Icon.constants.js +27 -0
- package/build/primitives/Icon/Icon.constants.js.map +1 -0
- package/build/primitives/Icon/Icon.js +34 -0
- package/build/primitives/Icon/Icon.js.map +1 -0
- package/build/primitives/Icon/Icon.module.css +11 -0
- package/build/primitives/Icon/__tests__/__snapshots__/Icon.test.js.snap +133 -0
- package/build/primitives/Icon/index.js +31 -0
- package/build/primitives/Icon/index.js.map +1 -0
- package/build/primitives/Input/Input.js +66 -0
- package/build/primitives/Input/Input.js.map +1 -0
- package/build/primitives/Input/Input.module.css +25 -0
- package/build/primitives/Input/__tests__/__snapshots__/Input.test.js.snap +74 -0
- package/build/primitives/Input/helpers/index.js +19 -0
- package/build/primitives/Input/helpers/index.js.map +1 -0
- package/build/primitives/Input/helpers/parseValue.js +17 -0
- package/build/primitives/Input/helpers/parseValue.js.map +1 -0
- package/build/primitives/Input/index.js +19 -0
- package/build/primitives/Input/index.js.map +1 -0
- package/build/primitives/Pressable/Pressable.constants.js +9 -0
- package/build/primitives/Pressable/Pressable.constants.js.map +1 -0
- package/build/primitives/Pressable/Pressable.js +50 -0
- package/build/primitives/Pressable/Pressable.js.map +1 -0
- package/build/primitives/Pressable/Pressable.module.css +18 -0
- package/build/primitives/Pressable/__tests__/__snapshots__/Pressable.test.js.snap +53 -0
- package/build/primitives/Pressable/index.js +19 -0
- package/build/primitives/Pressable/index.js.map +1 -0
- package/build/primitives/ScrollView/ScrollView.js +89 -0
- package/build/primitives/ScrollView/ScrollView.js.map +1 -0
- package/build/primitives/ScrollView/ScrollView.module.css +35 -0
- package/build/primitives/ScrollView/__tests__/__snapshots__/ScrollView.test.js.snap +535 -0
- package/build/primitives/ScrollView/index.js +19 -0
- package/build/primitives/ScrollView/index.js.map +1 -0
- package/build/primitives/Text/Text.js +40 -0
- package/build/primitives/Text/Text.js.map +1 -0
- package/build/primitives/Text/Text.module.css +36 -0
- package/build/primitives/Text/__tests__/__snapshots__/Text.test.js.snap +102 -0
- package/build/primitives/Text/index.js +19 -0
- package/build/primitives/Text/index.js.map +1 -0
- package/build/primitives/View/View.js +36 -0
- package/build/primitives/View/View.js.map +1 -0
- package/build/primitives/View/View.module.css +16 -0
- package/build/primitives/View/__tests__/__snapshots__/View.test.js.snap +62 -0
- package/build/primitives/View/index.js +19 -0
- package/build/primitives/View/index.js.map +1 -0
- package/build/primitives/index.js +84 -0
- package/build/primitives/index.js.map +1 -0
- package/build/theme/default.theme.css +37 -0
- package/build/theme/helpers/camelcase.js +16 -0
- package/build/theme/helpers/camelcase.js.map +1 -0
- package/build/theme/helpers/index.js +19 -0
- package/build/theme/helpers/index.js.map +1 -0
- package/build/theme/index.js +19 -0
- package/build/theme/index.js.map +1 -0
- package/build/theme/theme.js +43 -0
- package/build/theme/theme.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# 💾 @mirai/ui
|
|
2
|
+
|
|
3
|
+
> React components library.
|
|
4
|
+
|
|
5
|
+
### 📦 Setup
|
|
6
|
+
|
|
7
|
+
Add the package in your project:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
yarn add @mirai/ui
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Primitives
|
|
14
|
+
|
|
15
|
+
### Icon
|
|
16
|
+
|
|
17
|
+
This primitive returns a span with an icon based on a mandatory string prop `name` with one of the following possible values: Left, Right, Up, Down, Close, CloseArrow, Plus, Minus, EyeOpen, EyeClose.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { Icon, View } from '@mirai/ui';
|
|
21
|
+
|
|
22
|
+
const MyComponent = () => (
|
|
23
|
+
<View>
|
|
24
|
+
<Icon name="Left" />
|
|
25
|
+
</View>
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Input
|
|
30
|
+
|
|
31
|
+
This primitive returns an input or a textarea based on the following props:
|
|
32
|
+
|
|
33
|
+
- `disabled:boolean` applying 'disabled' attribute
|
|
34
|
+
- `multiline:boolean` if true returning textarea
|
|
35
|
+
- `name:string` input name
|
|
36
|
+
- `type:string` type attribute value
|
|
37
|
+
- `onChange:function` executed when input value changes
|
|
38
|
+
- `onEnter:function` executed when user clicks on input
|
|
39
|
+
- `onError:function` executed once an error event fires
|
|
40
|
+
- `onLeave:function` executed on click outside the input
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { Input, View } from '@mirai/ui';
|
|
44
|
+
|
|
45
|
+
const MyComponent = () => (
|
|
46
|
+
<View>
|
|
47
|
+
<Input
|
|
48
|
+
required
|
|
49
|
+
minLength={8}
|
|
50
|
+
placeholder="Input"
|
|
51
|
+
value={primitive}
|
|
52
|
+
test={(value) => value.includes('something')}
|
|
53
|
+
onChange={() => console.log('change')}
|
|
54
|
+
onError={(error) => console.log('Error:', error)}
|
|
55
|
+
/>
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Pressable
|
|
61
|
+
|
|
62
|
+
This primitive returns pressable elements based on the following properties:
|
|
63
|
+
|
|
64
|
+
- `children:node`
|
|
65
|
+
- `disabled:boolean` disable attribute
|
|
66
|
+
- `tag:string` html tag applied to a primitive
|
|
67
|
+
- `onEnter:function` executed once the user hovers over the element
|
|
68
|
+
- `onLeave:function` executed once the user hovers away
|
|
69
|
+
- `onPress:function` executed on mouse click on the element
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { Icon, Pressable, View } from '@mirai/ui';
|
|
73
|
+
|
|
74
|
+
const MyComponent = () => (
|
|
75
|
+
<View>
|
|
76
|
+
<Pressable onPress={() => console.log('clicked')}>
|
|
77
|
+
<Icon name="Left" />
|
|
78
|
+
</Pressable>
|
|
79
|
+
</View>
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### ScrollView
|
|
84
|
+
|
|
85
|
+
This primitive is used to make vertically scrollable views and receives the following props:
|
|
86
|
+
|
|
87
|
+
- `behavior:string` type of scroll animation
|
|
88
|
+
- `children:node`
|
|
89
|
+
- `height:number` height value
|
|
90
|
+
- `horizontal:boolean` layout direction
|
|
91
|
+
- `scrollEventThrottle:number` scroll timeout value
|
|
92
|
+
- `scrollIndicator:boolean` if true the scroll indicator is shown
|
|
93
|
+
- `scrollTo:number` coordinate to scroll to
|
|
94
|
+
- `tag:string` html tag of resulting element
|
|
95
|
+
- `width:number` width value
|
|
96
|
+
- `onscroll:function` executed when user scrolls over the element
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
import { ScrollView, View } from '@mirai/ui';
|
|
100
|
+
|
|
101
|
+
const MyComponent = ({ isDesktop }) => (
|
|
102
|
+
<ScrollView horizontal={isDesktop} onScroll={() => console.log('scrolling')}>
|
|
103
|
+
<View>Box 1</View>
|
|
104
|
+
<View>Box 2</View>
|
|
105
|
+
</ScrollView>
|
|
106
|
+
);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Text
|
|
110
|
+
|
|
111
|
+
A primitive for displaying text. It receives the following props:
|
|
112
|
+
|
|
113
|
+
- `action:boolean` modifying font-size
|
|
114
|
+
- `bold:boolean` modifying font-weight
|
|
115
|
+
- `children:string`
|
|
116
|
+
- `headline:boolean` modifying font-size
|
|
117
|
+
- `lighten:boolean` modifying text color
|
|
118
|
+
- `upperCase:boolean` switching text to upper case
|
|
119
|
+
- `small:boolean` modifying font-size
|
|
120
|
+
- `tag:string` html tag of resulting element
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import { Text, View } from '@mirai/ui';
|
|
124
|
+
|
|
125
|
+
const MyComponent = ({ headerText }) => (
|
|
126
|
+
<View>
|
|
127
|
+
<Text bold upperCase headline>
|
|
128
|
+
{headerText}
|
|
129
|
+
</Text>
|
|
130
|
+
</View>
|
|
131
|
+
);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### View
|
|
135
|
+
|
|
136
|
+
This primitive works as a container for displaying layout. It receives the following properties:
|
|
137
|
+
|
|
138
|
+
- `children:node`
|
|
139
|
+
- `fit:boolean` sets width CSS property as 'fit-content' if true
|
|
140
|
+
- `row:boolean` sets flex-direction as 'row' if true
|
|
141
|
+
- `tag:string` html tag of resulting element
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
import { Text, View } from '@mirai/ui';
|
|
145
|
+
|
|
146
|
+
const MyComponent = ({ headerText }) => (
|
|
147
|
+
<View row>
|
|
148
|
+
<Text bold upperCase headline>
|
|
149
|
+
{headerText}
|
|
150
|
+
</Text>
|
|
151
|
+
<View fit>Lorem ipsum very long text</View>
|
|
152
|
+
</View>
|
|
153
|
+
);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Components
|
|
157
|
+
|
|
158
|
+
React components assembled with primitives.
|
|
159
|
+
|
|
160
|
+
### Button
|
|
161
|
+
|
|
162
|
+
A button component that receives the following props:
|
|
163
|
+
|
|
164
|
+
- `children:node|string`
|
|
165
|
+
- `disabled:boolean` applying 'disabled' attribute
|
|
166
|
+
- `large:boolean` modifying the button size
|
|
167
|
+
- `small:boolean` modifying the button size
|
|
168
|
+
- `squared:boolean` if true gives rectangular shape to the button (false by default)
|
|
169
|
+
- `tag:string` html tag of resulting element ('button' by default)
|
|
170
|
+
- `onEnter:function` executed when the user hovers over
|
|
171
|
+
- `onLeave:function` executed when the user hovers away
|
|
172
|
+
- `onPress:function` executed on mouse click on the element
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import { Button } from '@mirai/ui';
|
|
176
|
+
|
|
177
|
+
const MyComponent = (props) => {
|
|
178
|
+
const handleButtonClick = () => console.log('click');
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<>
|
|
182
|
+
<Button large onPress={handleButtonClick} />
|
|
183
|
+
</>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Calendar
|
|
189
|
+
|
|
190
|
+
A calendar component that receives the following props:
|
|
191
|
+
|
|
192
|
+
- `captions:object` captions to be placed into calendar cells
|
|
193
|
+
- `disabledDates:[string]` dates to be shown as unavailable and can't be selected
|
|
194
|
+
- `disabledPast:boolean` past dates to be shown as unavailable and can't be selected
|
|
195
|
+
- `disabledWeekends` boolean: weekends to be shown as unavailable and can't be selected
|
|
196
|
+
- `format:string` date display format (e.g. "DD/MM/YYYY")
|
|
197
|
+
- `from:string` date in specific format (e.g. "31/03/2022")
|
|
198
|
+
- `months:number` number of months to be visible
|
|
199
|
+
- `locale:string` locale value
|
|
200
|
+
- `range:boolean` Enable range selection
|
|
201
|
+
- `rangeDays:number`
|
|
202
|
+
- `to:string` date in specific format (e.g. "31/03/2022")
|
|
203
|
+
- `value:string|[string]`
|
|
204
|
+
- `onChange:function` executed when input value changes
|
|
205
|
+
- `onFocus:function` executed on calendar cell hover
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
import { Calendar } from '@mirai/ui';
|
|
209
|
+
|
|
210
|
+
const MyComponent = props => {
|
|
211
|
+
const [value, setValue] = useState([]);
|
|
212
|
+
const [from, to] = value;
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<Calendar
|
|
216
|
+
captions={
|
|
217
|
+
'2022/03/31': '10.95$',
|
|
218
|
+
'2022/04/18': '510.95$',
|
|
219
|
+
'2022/04/20': '10.95$',
|
|
220
|
+
'2022/04/24': '9.95$',
|
|
221
|
+
}
|
|
222
|
+
disabledDates={['2022/04/14', '2022/04/25', '2022/04/29', '2022/04/30']}
|
|
223
|
+
format="DD/MM/YYYY"
|
|
224
|
+
months={2}
|
|
225
|
+
from={from}
|
|
226
|
+
to={to}
|
|
227
|
+
onChange={setValue}
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### InputNumber
|
|
234
|
+
|
|
235
|
+
Input number component controling the value with 2 buttons. Receives the following props:
|
|
236
|
+
|
|
237
|
+
- `hint:string` brief message
|
|
238
|
+
- `label:string` input label
|
|
239
|
+
- `max:number` maximum input value
|
|
240
|
+
- `min:number` minimum input value
|
|
241
|
+
- `name:string` input name attribute (required)
|
|
242
|
+
- `step:number` to be added/subtracted from value on each button click
|
|
243
|
+
- `value:number` input value
|
|
244
|
+
- `onChange:function` executed when input value changes
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
import { InputNumber } from '@mirai/ui';
|
|
248
|
+
|
|
249
|
+
const MyComponent = (props) => {
|
|
250
|
+
const [number, setNumber] = useState(1);
|
|
251
|
+
|
|
252
|
+
return <InputNumber min={1} name="candies" label="Candies" value={number} onChange={(next) => setNumber(next)} />;
|
|
253
|
+
};
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### InputText
|
|
257
|
+
|
|
258
|
+
Text input component receiving the following props:
|
|
259
|
+
|
|
260
|
+
- `disabled:boolean` applying 'disabled' attribute
|
|
261
|
+
- `error:boolean` true if error event fired
|
|
262
|
+
- `hint:string` brief message
|
|
263
|
+
- `label:string` input label
|
|
264
|
+
- `multiline:boolean` : if true returning textarea
|
|
265
|
+
- `name:string` : input name (required)
|
|
266
|
+
- `type:string` : input type attribute
|
|
267
|
+
- `onChange:function` : executed when input value changes
|
|
268
|
+
- `onEnter:function` executed when user clicks on input
|
|
269
|
+
- `onLeave:function` executed on click outside the input
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
import { InputText } from '@mirai/ui';
|
|
273
|
+
|
|
274
|
+
const MyComponent = (props) => {
|
|
275
|
+
const [text, setText] = useState();
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<InputText
|
|
279
|
+
name="text"
|
|
280
|
+
hint="hint"
|
|
281
|
+
label="My epic input"
|
|
282
|
+
placeholder="Some epic text"
|
|
283
|
+
type="text"
|
|
284
|
+
value={text}
|
|
285
|
+
onChange={(next) => setText(next)}
|
|
286
|
+
/>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Modal
|
|
292
|
+
|
|
293
|
+
A modal component receiving the following props:
|
|
294
|
+
|
|
295
|
+
- `children:node`
|
|
296
|
+
- `visible:boolean` if true modal is shown
|
|
297
|
+
- `onClose:function` executed once modal close button is clicked
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
import { Modal, View } from '@mirai/ui';
|
|
301
|
+
|
|
302
|
+
const MyComponent = (props) => {
|
|
303
|
+
const [visible, setVisible] = useState(false);
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<Modal visible={visible} onClose={() => setVisible(false)}>
|
|
307
|
+
<View>Some modal text</View>
|
|
308
|
+
</Modal>
|
|
309
|
+
);
|
|
310
|
+
};
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Theme
|
|
314
|
+
|
|
315
|
+
Styles can be customised by using Theme utility.
|
|
316
|
+
|
|
317
|
+
### get()
|
|
318
|
+
|
|
319
|
+
This method returns current theme settings (variables with values). This method receives as an optional parameter a string with a prefix (domain) to specify the scope ('--mirai-ui-' by default);
|
|
320
|
+
|
|
321
|
+
### set(variable, value, domain)
|
|
322
|
+
|
|
323
|
+
This method sets a value of the variable passed as a parameter.
|
|
324
|
+
|
|
325
|
+
```js
|
|
326
|
+
import { Button, Text, Theme } from '../../src';
|
|
327
|
+
|
|
328
|
+
export default () => {
|
|
329
|
+
const [theme, setTheme] = useState(Theme.get());
|
|
330
|
+
|
|
331
|
+
const handlePress = () => {
|
|
332
|
+
Theme.setVariable('base', '#222');
|
|
333
|
+
Theme.setVariable('content', '#fff');
|
|
334
|
+
Theme.setVariable('font', 'courier');
|
|
335
|
+
Theme.setVariable('accent', '#f0f');
|
|
336
|
+
setTheme(Theme.get());
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const { accent, spaceXL } = Theme.get();
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
<>
|
|
343
|
+
<Button style={{ marginTop: spaceXL, color: accent }} onPress={handlePress}>
|
|
344
|
+
Change Theme
|
|
345
|
+
</Button>
|
|
346
|
+
</>
|
|
347
|
+
);
|
|
348
|
+
};
|
|
349
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Button = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
16
|
+
var _helpers = require("../../helpers");
|
|
17
|
+
|
|
18
|
+
var _primitives = require("../../primitives");
|
|
19
|
+
|
|
20
|
+
var _ButtonModule = _interopRequireDefault(require("./Button.module.css"));
|
|
21
|
+
|
|
22
|
+
var _excluded = ["children", "disabled", "large", "outlined", "small", "squared", "tag"];
|
|
23
|
+
|
|
24
|
+
var Button = function Button(_ref) {
|
|
25
|
+
var children = _ref.children,
|
|
26
|
+
disabled = _ref.disabled,
|
|
27
|
+
large = _ref.large,
|
|
28
|
+
outlined = _ref.outlined,
|
|
29
|
+
small = _ref.small,
|
|
30
|
+
_ref$squared = _ref.squared,
|
|
31
|
+
squared = _ref$squared === void 0 ? false : _ref$squared,
|
|
32
|
+
_ref$tag = _ref.tag,
|
|
33
|
+
tag = _ref$tag === void 0 ? 'button' : _ref$tag,
|
|
34
|
+
others = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(_primitives.Pressable, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, others), {}, {
|
|
36
|
+
disabled: disabled,
|
|
37
|
+
tag: tag,
|
|
38
|
+
className: (0, _helpers.styles)(_ButtonModule.default.button, large && _ButtonModule.default.large, small && _ButtonModule.default.small, squared && _ButtonModule.default.squared, outlined && !disabled && _ButtonModule.default.outlined, disabled && _ButtonModule.default.disabled, others.className)
|
|
39
|
+
}), children);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.Button = Button;
|
|
43
|
+
Button.displayName = 'Component:Button';
|
|
44
|
+
//# sourceMappingURL=Button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Button/Button.jsx"],"names":["Button","children","disabled","large","outlined","small","squared","tag","others","React","createElement","Pressable","className","style","button","displayName"],"mappings":";;;;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,MAAGC,QAAH,QAAGA,QAAH;AAAA,MAAaC,QAAb,QAAaA,QAAb;AAAA,MAAuBC,KAAvB,QAAuBA,KAAvB;AAAA,MAA8BC,QAA9B,QAA8BA,QAA9B;AAAA,MAAwCC,KAAxC,QAAwCA,KAAxC;AAAA,0BAA+CC,OAA/C;AAAA,MAA+CA,OAA/C,6BAAyD,KAAzD;AAAA,sBAAgEC,GAAhE;AAAA,MAAgEA,GAAhE,yBAAsE,QAAtE;AAAA,MAAmFC,MAAnF;AAAA,sBACbC,eAAMC,aAAN,CACEC,qBADF,8DAGOH,MAHP;AAIIN,IAAAA,QAAQ,EAARA,QAJJ;AAKIK,IAAAA,GAAG,EAAHA,GALJ;AAMIK,IAAAA,SAAS,EAAE,qBACTC,sBAAMC,MADG,EAETX,KAAK,IAAIU,sBAAMV,KAFN,EAGTE,KAAK,IAAIQ,sBAAMR,KAHN,EAITC,OAAO,IAAIO,sBAAMP,OAJR,EAKTF,QAAQ,IAAI,CAACF,QAAb,IAAyBW,sBAAMT,QALtB,EAMTF,QAAQ,IAAIW,sBAAMX,QANT,EAOTM,MAAM,CAACI,SAPE;AANf,MAgBEX,QAhBF,CADa;AAAA,CAAf;;;AAoBAD,MAAM,CAACe,WAAP,GAAqB,kBAArB","sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Pressable } from '../../primitives';\nimport style from './Button.module.css';\n\nconst Button = ({ children, disabled, large, outlined, small, squared = false, tag = 'button', ...others }) =>\n React.createElement(\n Pressable,\n {\n ...others,\n disabled,\n tag,\n className: styles(\n style.button,\n large && style.large,\n small && style.small,\n squared && style.squared,\n outlined && !disabled && style.outlined,\n disabled && style.disabled,\n others.className,\n ),\n },\n children,\n );\n\nButton.displayName = 'Component:Button';\n\nButton.propTypes = {\n children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),\n disabled: PropTypes.bool,\n large: PropTypes.bool,\n outlined: PropTypes.bool,\n small: PropTypes.bool,\n squared: PropTypes.bool,\n tag: PropTypes.string,\n onEnter: PropTypes.func,\n onLeave: PropTypes.func,\n onPress: PropTypes.func,\n};\n\nexport { Button };\n"],"file":"Button.js"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--mirai-ui-button-color: var(--mirai-ui-accent);
|
|
3
|
+
--mirai-ui-button-color-active: rgba(255, 255, 255, 0.2);
|
|
4
|
+
--mirai-ui-button-color-focus: var(--mirai-ui-content);
|
|
5
|
+
--mirai-ui-button-color-text: var(--mirai-ui-base);
|
|
6
|
+
--mirai-ui-button-radius: var(--mirai-ui-border-radius);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.button {
|
|
10
|
+
align-items: center;
|
|
11
|
+
background-color: var(--mirai-ui-button-color);
|
|
12
|
+
border-radius: var(--mirai-ui-button-radius);
|
|
13
|
+
color: var(--mirai-ui-button-color-text);
|
|
14
|
+
display: flex;
|
|
15
|
+
font-family: var(--mirai-ui-font);
|
|
16
|
+
font-size: var(--mirai-ui-font-size-action);
|
|
17
|
+
font-weight: var(--mirai-ui-font-bold-weight);
|
|
18
|
+
justify-content: center;
|
|
19
|
+
padding: var(--mirai-ui-space-S) var(--mirai-ui-space-L);
|
|
20
|
+
transition: background-color var(--mirai-ui-motion-expand) var(--mirai-ui-motion-easing),
|
|
21
|
+
box-shadow var(--mirai-ui-motion-expand) var(--mirai-ui-motion-easing),
|
|
22
|
+
color var(--mirai-ui-motion-expand) var(--mirai-ui-motion-easing);
|
|
23
|
+
width: fit-content;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.disabled {
|
|
27
|
+
background-color: var(--mirai-ui-disabled);
|
|
28
|
+
color: var(--mirai-ui-lighten);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.outlined {
|
|
32
|
+
border: solid 1px var(--mirai-ui-button-color);
|
|
33
|
+
background-color: var(--mirai-ui-base);
|
|
34
|
+
color: var(--mirai-ui-button-color);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.button:not(.disabled):active {
|
|
38
|
+
box-shadow: inset 0 0 var(--mirai-ui-space-XXL) var(--mirai-ui-space-XXL) var(--mirai-ui-button-color-active);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.large:not(.squared) {
|
|
42
|
+
font-size: var(--mirai-ui-font-size-headline);
|
|
43
|
+
padding: var(--mirai-ui-space-M) var(--mirai-ui-space-XL);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.small:not(.squared) {
|
|
47
|
+
font-size: var(--mirai-ui-font-size-small);
|
|
48
|
+
padding: var(--mirai-ui-space-XS) var(--mirai-ui-space-S);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.squared {
|
|
52
|
+
padding: 0;
|
|
53
|
+
height: var(--mirai-ui-space-XL);
|
|
54
|
+
width: var(--mirai-ui-space-XL);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.squared.small {
|
|
58
|
+
height: var(--mirai-ui-space-L);
|
|
59
|
+
width: var(--mirai-ui-space-L);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.squared.large {
|
|
63
|
+
height: var(--mirai-ui-space-XXL);
|
|
64
|
+
width: var(--mirai-ui-space-XXL);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@media only screen and (max-width: 600px) {
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@media only screen and (min-width: 600px) {
|
|
71
|
+
.button:not(.disabled).outlined:hover {
|
|
72
|
+
border-color: var(--mirai-ui-button-color-hover);
|
|
73
|
+
color: var(--mirai-ui-button-color-focus);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.button:not(.disabled):not(.outlined):hover {
|
|
77
|
+
background-color: var(--mirai-ui-button-color-focus);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[` 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<button
|
|
6
|
+
class="pressable button squared"
|
|
7
|
+
>
|
|
8
|
+
children
|
|
9
|
+
</button>
|
|
10
|
+
</DocumentFragment>
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
exports[`component:<Button> inherit:className 1`] = `
|
|
14
|
+
<DocumentFragment>
|
|
15
|
+
<button
|
|
16
|
+
class="pressable button mirai"
|
|
17
|
+
>
|
|
18
|
+
children
|
|
19
|
+
</button>
|
|
20
|
+
</DocumentFragment>
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
exports[`component:<Button> prop:disabled 1`] = `
|
|
24
|
+
<DocumentFragment>
|
|
25
|
+
<button
|
|
26
|
+
class="pressable disabled button disabled"
|
|
27
|
+
disabled=""
|
|
28
|
+
>
|
|
29
|
+
children
|
|
30
|
+
</button>
|
|
31
|
+
</DocumentFragment>
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
exports[`component:<Button> prop:large 1`] = `
|
|
35
|
+
<DocumentFragment>
|
|
36
|
+
<button
|
|
37
|
+
class="pressable button large"
|
|
38
|
+
>
|
|
39
|
+
children
|
|
40
|
+
</button>
|
|
41
|
+
</DocumentFragment>
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
exports[`component:<Button> prop:outlined 1`] = `
|
|
45
|
+
<DocumentFragment>
|
|
46
|
+
<button
|
|
47
|
+
class="pressable button outlined"
|
|
48
|
+
>
|
|
49
|
+
children
|
|
50
|
+
</button>
|
|
51
|
+
</DocumentFragment>
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
exports[`component:<Button> prop:small 1`] = `
|
|
55
|
+
<DocumentFragment>
|
|
56
|
+
<button
|
|
57
|
+
class="pressable button small"
|
|
58
|
+
>
|
|
59
|
+
children
|
|
60
|
+
</button>
|
|
61
|
+
</DocumentFragment>
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
exports[`component:<Button> prop:squared & large 1`] = `
|
|
65
|
+
<DocumentFragment>
|
|
66
|
+
<button
|
|
67
|
+
class="pressable button large squared"
|
|
68
|
+
>
|
|
69
|
+
children
|
|
70
|
+
</button>
|
|
71
|
+
</DocumentFragment>
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
exports[`component:<Button> prop:squared & small 1`] = `
|
|
75
|
+
<DocumentFragment>
|
|
76
|
+
<button
|
|
77
|
+
class="pressable button small squared"
|
|
78
|
+
>
|
|
79
|
+
children
|
|
80
|
+
</button>
|
|
81
|
+
</DocumentFragment>
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
exports[`component:<Button> prop:tag 1`] = `
|
|
85
|
+
<DocumentFragment>
|
|
86
|
+
<a
|
|
87
|
+
class="pressable button"
|
|
88
|
+
>
|
|
89
|
+
children
|
|
90
|
+
</a>
|
|
91
|
+
</DocumentFragment>
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
exports[`component:<Button> renders 1`] = `
|
|
95
|
+
<DocumentFragment>
|
|
96
|
+
<button
|
|
97
|
+
class="pressable button"
|
|
98
|
+
>
|
|
99
|
+
children
|
|
100
|
+
</button>
|
|
101
|
+
</DocumentFragment>
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
exports[`component:<Button> testID 1`] = `
|
|
105
|
+
<DocumentFragment>
|
|
106
|
+
<button
|
|
107
|
+
class="pressable button"
|
|
108
|
+
data-testid="mirai"
|
|
109
|
+
>
|
|
110
|
+
children
|
|
111
|
+
</button>
|
|
112
|
+
</DocumentFragment>
|
|
113
|
+
`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _Button = require("./Button");
|
|
8
|
+
|
|
9
|
+
Object.keys(_Button).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _Button[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _Button[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Button/index.js"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './Button';\n"],"file":"index.js"}
|