@semcore/button 3.2.1 → 3.3.3-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/CHANGELOG.md +27 -0
- package/lib/cjs/Button.js +73 -98
- package/lib/cjs/Button.js.map +1 -1
- package/lib/cjs/SpinButton.js +15 -17
- package/lib/cjs/SpinButton.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/button.shadow.css +37 -37
- package/lib/es6/Button.js +77 -98
- package/lib/es6/Button.js.map +1 -1
- package/lib/es6/SpinButton.js +15 -18
- package/lib/es6/SpinButton.js.map +1 -1
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/button.shadow.css +37 -37
- package/lib/types/index.d.ts +52 -2
- package/package.json +5 -4
- package/src/Button.js +89 -0
- package/src/SpinButton.js +31 -0
- package/src/index.d.ts +52 -0
- package/src/{index.tsx → index.js} +0 -0
- package/src/style/button.shadow.css +37 -37
- package/lib/types/Button.d.ts +0 -68
- package/lib/types/SpinButton.d.ts +0 -25
- package/src/Button.tsx +0 -157
- package/src/SpinButton.tsx +0 -41
- package/tsconfig.json +0 -3
package/src/Button.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import createComponent, { Component, sstyled, Root } from '@semcore/core';
|
|
3
|
+
import { Box } from '@semcore/flex-box';
|
|
4
|
+
import { neighborLocationEnhance } from '@semcore/neighbor-location';
|
|
5
|
+
import keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
6
|
+
import addonTextChildren from '@semcore/utils/lib/addonTextChildren';
|
|
7
|
+
import SpinButton from './SpinButton';
|
|
8
|
+
|
|
9
|
+
import style from './style/button.shadow.css';
|
|
10
|
+
|
|
11
|
+
export const MAP_USE_DEFAULT_THEME = {
|
|
12
|
+
primary: 'info',
|
|
13
|
+
secondary: 'muted',
|
|
14
|
+
tertiary: 'info',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
class RootButton extends Component {
|
|
18
|
+
static displayName = 'Button';
|
|
19
|
+
static enhance = [keyboardFocusEnhance(), neighborLocationEnhance()];
|
|
20
|
+
static style = style;
|
|
21
|
+
static defaultProps = {
|
|
22
|
+
use: 'secondary',
|
|
23
|
+
size: 'm',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
getTextProps() {
|
|
27
|
+
const { size } = this.asProps;
|
|
28
|
+
return {
|
|
29
|
+
size,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getAddonProps() {
|
|
34
|
+
const { size } = this.asProps;
|
|
35
|
+
return {
|
|
36
|
+
size,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
render() {
|
|
41
|
+
const SButton = Root;
|
|
42
|
+
const SInner = Box;
|
|
43
|
+
const SSpin = Box;
|
|
44
|
+
const {
|
|
45
|
+
Children,
|
|
46
|
+
styles,
|
|
47
|
+
use,
|
|
48
|
+
theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
|
|
49
|
+
loading,
|
|
50
|
+
disabled = loading,
|
|
51
|
+
size,
|
|
52
|
+
addonLeft,
|
|
53
|
+
addonRight,
|
|
54
|
+
} = this.asProps;
|
|
55
|
+
|
|
56
|
+
const useTheme = use && theme ? `${use}-${theme}` : false;
|
|
57
|
+
return sstyled(styles)(
|
|
58
|
+
<SButton render={Box} type="button" tag="button" disabled={disabled} use:theme={useTheme}>
|
|
59
|
+
<SInner tag="span" loading={loading}>
|
|
60
|
+
{addonLeft ? <Button.Addon tag={addonLeft} /> : null}
|
|
61
|
+
{addonTextChildren(Children, Button.Text, Button.Addon)}
|
|
62
|
+
{addonRight ? <Button.Addon tag={addonRight} /> : null}
|
|
63
|
+
</SInner>
|
|
64
|
+
{loading && (
|
|
65
|
+
<SSpin tag="span">
|
|
66
|
+
<SpinButton centered size={size} theme={useTheme} />
|
|
67
|
+
</SSpin>
|
|
68
|
+
)}
|
|
69
|
+
</SButton>,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function Text(props) {
|
|
75
|
+
const SText = Root;
|
|
76
|
+
return sstyled(props.styles)(<SText render={Box} tag="span" />);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function Addon(props) {
|
|
80
|
+
const SAddon = Root;
|
|
81
|
+
return sstyled(props.styles)(<SAddon render={Box} tag="span" />);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const Button = createComponent(RootButton, {
|
|
85
|
+
Text,
|
|
86
|
+
Addon,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export default Button;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Spin from '@semcore/spin';
|
|
3
|
+
|
|
4
|
+
export const SPIN_SIZE_MAP = {
|
|
5
|
+
xl: 'm',
|
|
6
|
+
l: 's',
|
|
7
|
+
m: 'xs',
|
|
8
|
+
s: 'xxs',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const SPIN_THEME_MAP = {
|
|
12
|
+
'primary-info': 'invert',
|
|
13
|
+
'primary-success': 'invert',
|
|
14
|
+
'primary-warning': 'invert',
|
|
15
|
+
'primary-danger': 'invert',
|
|
16
|
+
'secondary-invert': 'invert',
|
|
17
|
+
'secondary-muted': 'gray40',
|
|
18
|
+
'secondary-info': 'light-blue',
|
|
19
|
+
'tertiary-invert': 'invert',
|
|
20
|
+
'tertiary-info': 'light-blue',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default function SpinButton({ theme, size, ...others }) {
|
|
24
|
+
return (
|
|
25
|
+
<Spin
|
|
26
|
+
size={typeof size == 'string' ? SPIN_SIZE_MAP[size] : size}
|
|
27
|
+
theme={typeof theme === 'string' ? SPIN_THEME_MAP[theme] || 'dark' : theme}
|
|
28
|
+
{...others}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
3
|
+
import { IKeyboardFocusProps } from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
4
|
+
import { IBoxProps } from '@semcore/flex-box';
|
|
5
|
+
import { INeighborItemProps } from '@semcore/neighbor-location';
|
|
6
|
+
|
|
7
|
+
export type ButtonSize = 'xl' | 'l' | 'm' | 's';
|
|
8
|
+
|
|
9
|
+
export interface IButtonProps extends IBoxProps, INeighborItemProps, IKeyboardFocusProps {
|
|
10
|
+
/**
|
|
11
|
+
* Button type
|
|
12
|
+
* @default secondary
|
|
13
|
+
*/
|
|
14
|
+
use?: 'primary' | 'secondary' | 'tertiary';
|
|
15
|
+
/** Button theme */
|
|
16
|
+
theme?: 'info' | 'success' | 'warning' | 'danger' | 'muted' | 'invert';
|
|
17
|
+
/** Button activity state */
|
|
18
|
+
active?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Button size
|
|
21
|
+
* @default m
|
|
22
|
+
*/
|
|
23
|
+
size?: ButtonSize;
|
|
24
|
+
/** Disabled button state */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** Loading button state */
|
|
27
|
+
loading?: boolean;
|
|
28
|
+
/** Tag for the left Addon */
|
|
29
|
+
addonLeft?: React.ElementType;
|
|
30
|
+
/** Tag for the right Addon */
|
|
31
|
+
addonRight?: React.ElementType;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IButtonTextProps extends IBoxProps {
|
|
35
|
+
size?: ButtonSize;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface IButtonAddonProps extends IBoxProps {
|
|
39
|
+
size?: ButtonSize;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IButtonContext {
|
|
43
|
+
getTextProps: PropGetterFn;
|
|
44
|
+
getAddonProps: PropGetterFn;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare const Button: (<T>(props: CProps<IButtonProps & T, IButtonContext>) => ReturnEl) & {
|
|
48
|
+
Text: <T>(props: IButtonTextProps & T) => ReturnEl;
|
|
49
|
+
Addon: <T>(props: IButtonAddonProps & T) => ReturnEl;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default Button;
|
|
File without changes
|
|
@@ -50,31 +50,31 @@ SButton[keyboardFocused] {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
SButton[size='s'] {
|
|
53
|
-
height:
|
|
54
|
-
min-width:
|
|
53
|
+
height: 18px;
|
|
54
|
+
min-width: 18px;
|
|
55
55
|
border-radius: 2px;
|
|
56
|
-
font-size:
|
|
56
|
+
font-size: 10px;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
SButton[size='m'] {
|
|
60
|
-
height:
|
|
61
|
-
min-width:
|
|
60
|
+
height: 26px;
|
|
61
|
+
min-width: 26px;
|
|
62
62
|
border-radius: 3px;
|
|
63
|
-
font-size:
|
|
63
|
+
font-size: 12px;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
SButton[size='l'] {
|
|
67
|
-
height:
|
|
68
|
-
min-width:
|
|
67
|
+
height: 32px;
|
|
68
|
+
min-width: 32px;
|
|
69
69
|
border-radius: 4px;
|
|
70
|
-
font-size:
|
|
70
|
+
font-size: 14px;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
SButton[size='xl'] {
|
|
74
|
-
height:
|
|
75
|
-
min-width:
|
|
74
|
+
height: 42px;
|
|
75
|
+
min-width: 42px;
|
|
76
76
|
border-radius: 5px;
|
|
77
|
-
font-size:
|
|
77
|
+
font-size: 16px;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
SButton[theme='primary-info'] {
|
|
@@ -295,27 +295,27 @@ SInner[loading] {
|
|
|
295
295
|
|
|
296
296
|
SText {
|
|
297
297
|
display: inline-flex;
|
|
298
|
-
line-height: 1.
|
|
298
|
+
line-height: 1.1;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
SText[size='s'] {
|
|
302
|
-
margin-left:
|
|
303
|
-
margin-right:
|
|
302
|
+
margin-left: 4px;
|
|
303
|
+
margin-right: 4px;
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
SText[size='m'] {
|
|
307
|
-
margin-left:
|
|
308
|
-
margin-right:
|
|
307
|
+
margin-left: 8px;
|
|
308
|
+
margin-right: 8px;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
SText[size='l'] {
|
|
312
|
-
margin-left:
|
|
313
|
-
margin-right:
|
|
312
|
+
margin-left: 8px;
|
|
313
|
+
margin-right: 8px;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
SText[size='xl'] {
|
|
317
|
-
margin-left:
|
|
318
|
-
margin-right:
|
|
317
|
+
margin-left: 12px;
|
|
318
|
+
margin-right: 12px;
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
SAddon {
|
|
@@ -326,60 +326,60 @@ SAddon {
|
|
|
326
326
|
|
|
327
327
|
SAddon[size='s'] {
|
|
328
328
|
&:not(:only-child):first-child {
|
|
329
|
-
margin-left:
|
|
329
|
+
margin-left: 4px;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
&:not(:only-child):last-child {
|
|
333
|
-
margin-right:
|
|
333
|
+
margin-right: 4px;
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
&:only-child {
|
|
337
|
-
margin-left:
|
|
338
|
-
margin-right:
|
|
337
|
+
margin-left: -2px;
|
|
338
|
+
margin-right: -2px;
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
SAddon[size='m'] {
|
|
343
343
|
&:not(:only-child):first-child {
|
|
344
|
-
margin-left:
|
|
344
|
+
margin-left: 8px;
|
|
345
345
|
}
|
|
346
346
|
|
|
347
347
|
&:not(:only-child):last-child {
|
|
348
|
-
margin-right:
|
|
348
|
+
margin-right: 8px;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
&:only-child {
|
|
352
|
-
margin-left:
|
|
353
|
-
margin-right:
|
|
352
|
+
margin-left: -4px;
|
|
353
|
+
margin-right: -4px;
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
SAddon[size='l'] {
|
|
358
358
|
&:not(:only-child):first-child {
|
|
359
|
-
margin-left:
|
|
359
|
+
margin-left: 8px;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
&:not(:only-child):last-child {
|
|
363
|
-
margin-right:
|
|
363
|
+
margin-right: 8px;
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
&:only-child {
|
|
367
|
-
margin-left:
|
|
368
|
-
margin-right:
|
|
367
|
+
margin-left: -4px;
|
|
368
|
+
margin-right: -4px;
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
SAddon[size='xl'] {
|
|
373
373
|
&:not(:only-child):first-child {
|
|
374
|
-
margin-left:
|
|
374
|
+
margin-left: 12px;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
&:not(:only-child):last-child {
|
|
378
|
-
margin-right:
|
|
378
|
+
margin-right: 12px;
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
&:only-child {
|
|
382
|
-
margin-left:
|
|
383
|
-
margin-right:
|
|
382
|
+
margin-left: -6px;
|
|
383
|
+
margin-right: -6px;
|
|
384
384
|
}
|
|
385
385
|
}
|
package/lib/types/Button.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from 'react';
|
|
2
|
-
import { IBoxProps } from '@semcore/flex-box';
|
|
3
|
-
import { Component, Merge, PropGetter } from '@semcore/core';
|
|
4
|
-
import { INeighborItemProps } from '@semcore/neighbor-location';
|
|
5
|
-
import { IKeyboardFocusProps } from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
6
|
-
export declare type ButtonSize = 'xl' | 'l' | 'm' | 's';
|
|
7
|
-
export interface IButtonProps extends IBoxProps, INeighborItemProps, IKeyboardFocusProps {
|
|
8
|
-
/**
|
|
9
|
-
* Button type
|
|
10
|
-
* @default secondary
|
|
11
|
-
*/
|
|
12
|
-
use?: 'primary' | 'secondary' | 'tertiary';
|
|
13
|
-
/** Button theme */
|
|
14
|
-
theme?: 'info' | 'success' | 'warning' | 'danger' | 'muted' | 'invert';
|
|
15
|
-
/** Button activity state */
|
|
16
|
-
active?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Button size
|
|
19
|
-
* @default m
|
|
20
|
-
*/
|
|
21
|
-
size?: ButtonSize;
|
|
22
|
-
/** Disabled button state */
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
/** Loading button state */
|
|
25
|
-
loading?: boolean;
|
|
26
|
-
/** Tag for the left Addon */
|
|
27
|
-
addonLeft?: React.ElementType;
|
|
28
|
-
/** Tag for the right Addon */
|
|
29
|
-
addonRight?: React.ElementType;
|
|
30
|
-
}
|
|
31
|
-
export interface IButtonTextProps extends IBoxProps {
|
|
32
|
-
size?: ButtonSize;
|
|
33
|
-
}
|
|
34
|
-
export interface IButtonAddonProps extends IBoxProps {
|
|
35
|
-
size?: ButtonSize;
|
|
36
|
-
}
|
|
37
|
-
export interface IButtonContext extends IButtonProps {
|
|
38
|
-
getTextProps: PropGetter<RootButton['getTextProps']>;
|
|
39
|
-
getAddonProps: PropGetter<RootButton['getAddonProps']>;
|
|
40
|
-
}
|
|
41
|
-
export declare const MAP_USE_DEFAULT_THEME: {
|
|
42
|
-
primary: string;
|
|
43
|
-
secondary: string;
|
|
44
|
-
tertiary: string;
|
|
45
|
-
};
|
|
46
|
-
declare class RootButton extends Component<IButtonProps> {
|
|
47
|
-
static displayName: string;
|
|
48
|
-
static enhance: ((props: any) => any)[];
|
|
49
|
-
static style: any;
|
|
50
|
-
static defaultProps: {
|
|
51
|
-
use: string;
|
|
52
|
-
size: string;
|
|
53
|
-
};
|
|
54
|
-
getTextProps(): {
|
|
55
|
-
size: "m" | "s" | "xl" | "l";
|
|
56
|
-
};
|
|
57
|
-
getAddonProps(): {
|
|
58
|
-
size: "m" | "s" | "xl" | "l";
|
|
59
|
-
};
|
|
60
|
-
render(): any;
|
|
61
|
-
}
|
|
62
|
-
declare const Button: import("@semcore/core").ComponentType<Merge<IButtonProps, React.HTMLAttributes<HTMLButtonElement>>, {
|
|
63
|
-
Addon: Merge<IButtonAddonProps, HTMLAttributes<HTMLSpanElement>>;
|
|
64
|
-
Text: Merge<IButtonTextProps, HTMLAttributes<HTMLSpanElement>>;
|
|
65
|
-
}, IButtonContext, {
|
|
66
|
-
[key: string]: (arg: unknown) => void;
|
|
67
|
-
}, null>;
|
|
68
|
-
export default Button;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
-
import { Merge } from '@semcore/core';
|
|
3
|
-
export declare const SPIN_SIZE_MAP: {
|
|
4
|
-
xl: string;
|
|
5
|
-
l: string;
|
|
6
|
-
m: string;
|
|
7
|
-
s: string;
|
|
8
|
-
};
|
|
9
|
-
export declare enum SPIN_THEME_MAP {
|
|
10
|
-
'primary-info' = "invert",
|
|
11
|
-
'primary-success' = "invert",
|
|
12
|
-
'primary-warning' = "invert",
|
|
13
|
-
'primary-danger' = "invert",
|
|
14
|
-
'secondary-invert' = "invert",
|
|
15
|
-
'secondary-muted' = "gray40",
|
|
16
|
-
'secondary-info' = "light-blue",
|
|
17
|
-
'tertiary-invert' = "invert",
|
|
18
|
-
'tertiary-info' = "light-blue"
|
|
19
|
-
}
|
|
20
|
-
export interface ISpinButtonProps {
|
|
21
|
-
size?: 'xl' | 'l' | 'm' | 's' | false;
|
|
22
|
-
theme?: string | false;
|
|
23
|
-
centered?: boolean;
|
|
24
|
-
}
|
|
25
|
-
export default function SpinButton(props: Merge<ISpinButtonProps, HTMLAttributes<HTMLSpanElement>>): JSX.Element;
|
package/src/Button.tsx
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from 'react';
|
|
2
|
-
import { Box, IBoxProps } from '@semcore/flex-box';
|
|
3
|
-
import createComponent, {
|
|
4
|
-
Component,
|
|
5
|
-
IFunctionProps,
|
|
6
|
-
Merge,
|
|
7
|
-
PropGetter,
|
|
8
|
-
styled,
|
|
9
|
-
} from '@semcore/core';
|
|
10
|
-
import { INeighborItemProps, neighborLocationEnhance } from '@semcore/neighbor-location';
|
|
11
|
-
import keyboardFocusEnhance, {
|
|
12
|
-
IKeyboardFocusProps,
|
|
13
|
-
} from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
14
|
-
import addonTextChildren from '@semcore/utils/lib/addonTextChildren';
|
|
15
|
-
import SpinButton from './SpinButton';
|
|
16
|
-
|
|
17
|
-
import style from './style/button.shadow.css';
|
|
18
|
-
|
|
19
|
-
export type ButtonSize = 'xl' | 'l' | 'm' | 's';
|
|
20
|
-
|
|
21
|
-
export interface IButtonProps extends IBoxProps, INeighborItemProps, IKeyboardFocusProps {
|
|
22
|
-
/**
|
|
23
|
-
* Button type
|
|
24
|
-
* @default secondary
|
|
25
|
-
*/
|
|
26
|
-
use?: 'primary' | 'secondary' | 'tertiary';
|
|
27
|
-
/** Button theme */
|
|
28
|
-
theme?: 'info' | 'success' | 'warning' | 'danger' | 'muted' | 'invert';
|
|
29
|
-
/** Button activity state */
|
|
30
|
-
active?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Button size
|
|
33
|
-
* @default m
|
|
34
|
-
*/
|
|
35
|
-
size?: ButtonSize;
|
|
36
|
-
/** Disabled button state */
|
|
37
|
-
disabled?: boolean;
|
|
38
|
-
/** Loading button state */
|
|
39
|
-
loading?: boolean;
|
|
40
|
-
/** Tag for the left Addon */
|
|
41
|
-
addonLeft?: React.ElementType;
|
|
42
|
-
/** Tag for the right Addon */
|
|
43
|
-
addonRight?: React.ElementType;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface IButtonTextProps extends IBoxProps {
|
|
47
|
-
size?: ButtonSize;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface IButtonAddonProps extends IBoxProps {
|
|
51
|
-
size?: ButtonSize;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface IButtonContext extends IButtonProps {
|
|
55
|
-
getTextProps: PropGetter<RootButton['getTextProps']>;
|
|
56
|
-
getAddonProps: PropGetter<RootButton['getAddonProps']>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const MAP_USE_DEFAULT_THEME = {
|
|
60
|
-
primary: 'info',
|
|
61
|
-
secondary: 'muted',
|
|
62
|
-
tertiary: 'info',
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
class RootButton extends Component<IButtonProps> {
|
|
66
|
-
static displayName = 'Button';
|
|
67
|
-
static enhance = [keyboardFocusEnhance(), neighborLocationEnhance()];
|
|
68
|
-
static style = style;
|
|
69
|
-
static defaultProps = {
|
|
70
|
-
use: 'secondary',
|
|
71
|
-
size: 'm',
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
getTextProps() {
|
|
75
|
-
const { size } = this.asProps;
|
|
76
|
-
return {
|
|
77
|
-
size,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getAddonProps() {
|
|
82
|
-
const { size } = this.asProps;
|
|
83
|
-
return {
|
|
84
|
-
size,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
render() {
|
|
89
|
-
const { Root: SButton } = this;
|
|
90
|
-
const SInner = Box;
|
|
91
|
-
const SSpin = Box;
|
|
92
|
-
const {
|
|
93
|
-
Children,
|
|
94
|
-
styles,
|
|
95
|
-
use,
|
|
96
|
-
theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
|
|
97
|
-
loading,
|
|
98
|
-
disabled = loading,
|
|
99
|
-
active,
|
|
100
|
-
size,
|
|
101
|
-
addonLeft,
|
|
102
|
-
addonRight,
|
|
103
|
-
keyboardFocused,
|
|
104
|
-
neighborLocation,
|
|
105
|
-
} = this.asProps;
|
|
106
|
-
|
|
107
|
-
const useTheme = use && theme ? `${use}-${theme}` : false;
|
|
108
|
-
return styled(styles)(
|
|
109
|
-
<SButton
|
|
110
|
-
render={Box}
|
|
111
|
-
type="button"
|
|
112
|
-
tag="button"
|
|
113
|
-
disabled={disabled}
|
|
114
|
-
theme={useTheme}
|
|
115
|
-
size={size}
|
|
116
|
-
active={active}
|
|
117
|
-
neighborLocation={neighborLocation}
|
|
118
|
-
keyboardFocused={keyboardFocused}
|
|
119
|
-
>
|
|
120
|
-
<SInner tag="span" loading={loading}>
|
|
121
|
-
{addonLeft ? <Button.Addon tag={addonLeft} /> : null}
|
|
122
|
-
{addonTextChildren(Children, Button.Text, Button.Addon)}
|
|
123
|
-
{addonRight ? <Button.Addon tag={addonRight} /> : null}
|
|
124
|
-
</SInner>
|
|
125
|
-
{loading && (
|
|
126
|
-
<SSpin tag="span">
|
|
127
|
-
<SpinButton centered size={size} theme={useTheme} />
|
|
128
|
-
</SSpin>
|
|
129
|
-
)}
|
|
130
|
-
</SButton>,
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function Text(props: IFunctionProps<IButtonTextProps>) {
|
|
136
|
-
const { Root: SText, size, styles } = props;
|
|
137
|
-
return styled(styles)(<SText render={Box} tag="span" size={size} />);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function Addon(props: IFunctionProps<IButtonAddonProps>) {
|
|
141
|
-
const { Root: SAddon, size, styles } = props;
|
|
142
|
-
return styled(styles)(<SAddon render={Box} tag="span" size={size} />);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const Button = createComponent<
|
|
146
|
-
Merge<IButtonProps, HTMLAttributes<HTMLButtonElement>>,
|
|
147
|
-
{
|
|
148
|
-
Addon: Merge<IButtonAddonProps, HTMLAttributes<HTMLSpanElement>>;
|
|
149
|
-
Text: Merge<IButtonTextProps, HTMLAttributes<HTMLSpanElement>>;
|
|
150
|
-
},
|
|
151
|
-
IButtonContext
|
|
152
|
-
>(RootButton, {
|
|
153
|
-
Text,
|
|
154
|
-
Addon,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
export default Button;
|
package/src/SpinButton.tsx
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from 'react';
|
|
2
|
-
import { Merge } from '@semcore/core';
|
|
3
|
-
import Spin, { ISpinProps } from '@semcore/spin';
|
|
4
|
-
|
|
5
|
-
export const SPIN_SIZE_MAP = {
|
|
6
|
-
xl: 'm',
|
|
7
|
-
l: 's',
|
|
8
|
-
m: 'xs',
|
|
9
|
-
s: 'xxs',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export enum SPIN_THEME_MAP {
|
|
13
|
-
'primary-info' = 'invert',
|
|
14
|
-
'primary-success' = 'invert',
|
|
15
|
-
'primary-warning' = 'invert',
|
|
16
|
-
'primary-danger' = 'invert',
|
|
17
|
-
'secondary-invert' = 'invert',
|
|
18
|
-
'secondary-muted' = 'gray40',
|
|
19
|
-
'secondary-info' = 'light-blue',
|
|
20
|
-
'tertiary-invert' = 'invert',
|
|
21
|
-
'tertiary-info' = 'light-blue',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ISpinButtonProps {
|
|
25
|
-
size?: 'xl' | 'l' | 'm' | 's' | false;
|
|
26
|
-
theme?: string | false;
|
|
27
|
-
centered?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default function SpinButton(
|
|
31
|
-
props: Merge<ISpinButtonProps, HTMLAttributes<HTMLSpanElement>>,
|
|
32
|
-
) {
|
|
33
|
-
const { theme, size, ...others } = props;
|
|
34
|
-
return (
|
|
35
|
-
<Spin
|
|
36
|
-
size={(typeof size == 'string' ? SPIN_SIZE_MAP[size] : size) as ISpinProps['size']}
|
|
37
|
-
theme={typeof theme === 'string' ? SPIN_THEME_MAP[theme] || 'dark' : theme}
|
|
38
|
-
{...others}
|
|
39
|
-
/>
|
|
40
|
-
);
|
|
41
|
-
}
|
package/tsconfig.json
DELETED