@semcore/button 17.0.0-prerelease.30 → 17.0.0-prerelease.31
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 +1 -1
- package/lib/cjs/component/Button/Button.js +117 -13
- package/lib/cjs/component/Button/Button.js.map +1 -1
- package/lib/cjs/component/Button/Button.type.js.map +1 -1
- package/lib/cjs/component/Button/SpinButton.js.map +1 -0
- package/lib/cjs/component/ButtonLink/ButtonLink.js +28 -53
- package/lib/cjs/component/ButtonLink/ButtonLink.js.map +1 -1
- package/lib/cjs/component/ButtonLink/ButtonLink.type.js.map +1 -1
- package/lib/cjs/component/ButtonLink/buttonLink.shadow.css +10 -140
- package/lib/cjs/index.js +3 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/es6/component/Button/Button.js +119 -15
- package/lib/es6/component/Button/Button.js.map +1 -1
- package/lib/es6/component/Button/Button.type.js.map +1 -1
- package/lib/es6/component/Button/SpinButton.js.map +1 -0
- package/lib/es6/component/ButtonLink/ButtonLink.js +29 -55
- package/lib/es6/component/ButtonLink/ButtonLink.js.map +1 -1
- package/lib/es6/component/ButtonLink/ButtonLink.type.js.map +1 -1
- package/lib/es6/component/ButtonLink/buttonLink.shadow.css +10 -140
- package/lib/es6/index.js +1 -2
- package/lib/es6/index.js.map +1 -1
- package/lib/esm/component/Button/Button.mjs +117 -12
- package/lib/esm/component/ButtonLink/ButtonLink.mjs +29 -53
- package/lib/esm/component/ButtonLink/buttonLink.shadow.css +10 -140
- package/lib/esm/index.mjs +1 -2
- package/lib/types/component/Button/Button.d.ts +28 -1
- package/lib/types/component/Button/Button.type.d.ts +39 -19
- package/lib/types/component/ButtonLink/ButtonLink.type.d.ts +14 -16
- package/lib/types/index.d.ts +1 -2
- package/package.json +7 -7
- package/src/component/Button/Button.tsx +144 -7
- package/src/component/Button/Button.type.ts +45 -30
- package/src/component/ButtonLink/ButtonLink.tsx +22 -27
- package/src/component/ButtonLink/ButtonLink.type.ts +14 -22
- package/src/component/ButtonLink/buttonLink.shadow.css +10 -140
- package/src/index.ts +1 -2
- package/lib/cjs/component/AbstractButton/AbstractButton.js +0 -136
- package/lib/cjs/component/AbstractButton/AbstractButton.js.map +0 -1
- package/lib/cjs/component/AbstractButton/AbstractButton.type.js +0 -2
- package/lib/cjs/component/AbstractButton/AbstractButton.type.js.map +0 -1
- package/lib/cjs/component/AbstractButton/SpinButton.js.map +0 -1
- package/lib/es6/component/AbstractButton/AbstractButton.js +0 -129
- package/lib/es6/component/AbstractButton/AbstractButton.js.map +0 -1
- package/lib/es6/component/AbstractButton/AbstractButton.type.js +0 -2
- package/lib/es6/component/AbstractButton/AbstractButton.type.js.map +0 -1
- package/lib/es6/component/AbstractButton/SpinButton.js.map +0 -1
- package/lib/esm/component/AbstractButton/AbstractButton.mjs +0 -129
- package/lib/types/component/AbstractButton/AbstractButton.d.ts +0 -21
- package/lib/types/component/AbstractButton/AbstractButton.type.d.ts +0 -37
- package/src/component/AbstractButton/AbstractButton.tsx +0 -171
- package/src/component/AbstractButton/AbstractButton.type.ts +0 -43
- /package/lib/cjs/component/{AbstractButton → Button}/SpinButton.js +0 -0
- /package/lib/es6/component/{AbstractButton → Button}/SpinButton.js +0 -0
- /package/lib/esm/component/{AbstractButton → Button}/SpinButton.mjs +0 -0
- /package/lib/types/component/{AbstractButton → Button}/SpinButton.d.ts +0 -0
- /package/src/component/{AbstractButton → Button}/SpinButton.tsx +0 -0
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import { Box } from '@semcore/base-components';
|
|
2
|
-
import {
|
|
1
|
+
import { NeighborLocation, Box, Hint } from '@semcore/base-components';
|
|
2
|
+
import { Component, CORE_INSTANCE, createComponent, Root, sstyled } from '@semcore/core';
|
|
3
|
+
import addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';
|
|
4
|
+
import hasLabels from '@semcore/core/lib/utils/hasLabels';
|
|
5
|
+
import logger from '@semcore/core/lib/utils/logger';
|
|
3
6
|
import { Text } from '@semcore/typography';
|
|
4
7
|
import React from 'react';
|
|
5
8
|
|
|
6
9
|
import style from './button.shadow.css';
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
10
|
+
import type { ButtonProps, ButtonAddonProps, ButtonTextProps, ButtonComponent } from './Button.type';
|
|
11
|
+
import SpinButton from './SpinButton';
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
export const MAP_USE_DEFAULT_THEME: Record<string, string> = {
|
|
14
|
+
primary: 'info',
|
|
15
|
+
secondary: 'muted',
|
|
16
|
+
tertiary: 'info',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type State = {
|
|
20
|
+
ariaLabelledByContent: null | string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class RootButton extends Component<ButtonProps, [], never, {}, State> {
|
|
11
24
|
static displayName = 'Button';
|
|
12
25
|
static style = style;
|
|
13
26
|
static defaultProps = {
|
|
@@ -15,8 +28,132 @@ class RootButton extends AbstractButton {
|
|
|
15
28
|
size: 'm',
|
|
16
29
|
};
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
containerRef = React.createRef<HTMLButtonElement>();
|
|
32
|
+
|
|
33
|
+
state: State = {
|
|
34
|
+
ariaLabelledByContent: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
getTextProps() {
|
|
38
|
+
const { size } = this.asProps;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
size,
|
|
42
|
+
'hint:triggerRef': this.containerRef,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getAddonProps() {
|
|
47
|
+
const { size } = this.asProps;
|
|
48
|
+
return {
|
|
49
|
+
size,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
componentDidMount() {
|
|
54
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
55
|
+
logger.warn(
|
|
56
|
+
this.containerRef.current && !hasLabels(this.containerRef.current) && !this.asProps.title,
|
|
57
|
+
`'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`,
|
|
58
|
+
this.asProps['data-ui-name'] || RootButton.displayName,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ariaLabelledby = this.asProps['aria-labelledby'];
|
|
63
|
+
|
|
64
|
+
if (ariaLabelledby) {
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
this.setState({
|
|
67
|
+
ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? '',
|
|
68
|
+
});
|
|
69
|
+
}, 0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
render() {
|
|
74
|
+
const {
|
|
75
|
+
styles,
|
|
76
|
+
use,
|
|
77
|
+
theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
|
|
78
|
+
loading,
|
|
79
|
+
disabled = loading,
|
|
80
|
+
size,
|
|
81
|
+
neighborLocation,
|
|
82
|
+
children,
|
|
83
|
+
title,
|
|
84
|
+
['aria-label']: ariaLabel,
|
|
85
|
+
Children,
|
|
86
|
+
addonLeft: AddonLeft,
|
|
87
|
+
addonRight: AddonRight,
|
|
88
|
+
hintPlacement,
|
|
89
|
+
} = this.asProps;
|
|
90
|
+
const SButton = Root;
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
const Button = this[CORE_INSTANCE];
|
|
93
|
+
const useTheme = use && theme ? `${use}-${theme}` : false;
|
|
94
|
+
const SInner = Box;
|
|
95
|
+
const SSpin = Box;
|
|
96
|
+
const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';
|
|
97
|
+
|
|
98
|
+
const showHint = (children === undefined || title);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<NeighborLocation.Detect neighborLocation={neighborLocation}>
|
|
102
|
+
{(neighborLocation) => {
|
|
103
|
+
return sstyled(styles)(
|
|
104
|
+
<>
|
|
105
|
+
<SButton
|
|
106
|
+
render={Box}
|
|
107
|
+
invertOutline={theme === 'invert'}
|
|
108
|
+
type='button'
|
|
109
|
+
tag='button'
|
|
110
|
+
tabIndex={0}
|
|
111
|
+
disabled={disabled}
|
|
112
|
+
use:theme={useTheme}
|
|
113
|
+
ref={this.containerRef}
|
|
114
|
+
aria-busy={loading}
|
|
115
|
+
__excludeProps={['title']}
|
|
116
|
+
aria-label={showHint ? buttonAriaLabel : undefined}
|
|
117
|
+
neighborLocation={neighborLocation}
|
|
118
|
+
>
|
|
119
|
+
{/* @ts-ignore */}
|
|
120
|
+
<SInner tag='span' loading={loading} data-ui-name={`${this.asProps['data-ui-name']}.InnerWrapper`}>
|
|
121
|
+
{AddonLeft
|
|
122
|
+
? (
|
|
123
|
+
<Button.Addon>
|
|
124
|
+
<AddonLeft />
|
|
125
|
+
</Button.Addon>
|
|
126
|
+
)
|
|
127
|
+
: null}
|
|
128
|
+
{addonTextChildren(Children, Button.Text, Button.Addon)}
|
|
129
|
+
{AddonRight
|
|
130
|
+
? (
|
|
131
|
+
<Button.Addon>
|
|
132
|
+
<AddonRight />
|
|
133
|
+
</Button.Addon>
|
|
134
|
+
)
|
|
135
|
+
: null}
|
|
136
|
+
</SInner>
|
|
137
|
+
{loading && (
|
|
138
|
+
<SSpin tag='span'>
|
|
139
|
+
<SpinButton centered size={size} theme={useTheme} />
|
|
140
|
+
</SSpin>
|
|
141
|
+
)}
|
|
142
|
+
</SButton>
|
|
143
|
+
{showHint && (
|
|
144
|
+
<Hint
|
|
145
|
+
triggerRef={this.containerRef}
|
|
146
|
+
timeout={[250, 50]}
|
|
147
|
+
placement={hintPlacement}
|
|
148
|
+
>
|
|
149
|
+
{buttonAriaLabel}
|
|
150
|
+
</Hint>
|
|
151
|
+
)}
|
|
152
|
+
</>,
|
|
153
|
+
);
|
|
154
|
+
}}
|
|
155
|
+
</NeighborLocation.Detect>
|
|
156
|
+
);
|
|
20
157
|
}
|
|
21
158
|
}
|
|
22
159
|
|
|
@@ -1,33 +1,48 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import type { BoxProps, NeighborItemProps, SimpleHintPopperProps } from '@semcore/base-components';
|
|
2
|
+
import type { Intergalactic, PropGetterFn } from '@semcore/core';
|
|
3
|
+
import type { TextProps } from '@semcore/typography';
|
|
4
|
+
import type React from 'react';
|
|
5
|
+
|
|
6
|
+
export type ButtonProps = BoxProps &
|
|
7
|
+
NeighborItemProps & {
|
|
8
|
+
/** Button activity state */
|
|
9
|
+
active?: boolean;
|
|
10
|
+
/** Disabled button state */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Loading button state */
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
/** Tag for the left Addon */
|
|
15
|
+
addonLeft?: React.ElementType;
|
|
16
|
+
/** Tag for the right Addon */
|
|
17
|
+
addonRight?: React.ElementType;
|
|
18
|
+
/**
|
|
19
|
+
* Placement for hint
|
|
20
|
+
* @default top
|
|
21
|
+
*/
|
|
22
|
+
hintPlacement?: SimpleHintPopperProps['placement'];
|
|
23
|
+
|
|
24
|
+
/** Button size.
|
|
25
|
+
* @default `m`
|
|
26
|
+
*/
|
|
27
|
+
size?: 'l' | 'm';
|
|
28
|
+
/** Button usage.
|
|
29
|
+
* @default `primary`
|
|
30
|
+
*/
|
|
31
|
+
use?: 'primary' | 'secondary' | 'tertiary';
|
|
32
|
+
/** Button theme.
|
|
33
|
+
* @default undefined
|
|
34
|
+
*/
|
|
35
|
+
theme?: 'info' | 'success' | 'brand' | 'danger' | 'muted' | 'invert';
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type ButtonTextProps = TextProps;
|
|
39
|
+
|
|
40
|
+
export type ButtonAddonProps = BoxProps;
|
|
41
|
+
|
|
42
|
+
export type ButtonContext = {
|
|
43
|
+
getTextProps: PropGetterFn;
|
|
44
|
+
getAddonProps: PropGetterFn;
|
|
45
|
+
};
|
|
31
46
|
|
|
32
47
|
export type ButtonChildren = {
|
|
33
48
|
Text: Intergalactic.Component<'span', ButtonTextProps>;
|
|
@@ -1,42 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import resolveColorEnhance from '@semcore/core/lib/utils/enhances/resolveColorEnhance';
|
|
4
|
-
import { Text } from '@semcore/typography';
|
|
1
|
+
import { createComponent, sstyled, Root, Component } from '@semcore/core';
|
|
2
|
+
import Link from '@semcore/link';
|
|
5
3
|
import React from 'react';
|
|
6
4
|
|
|
7
5
|
import style from './buttonLink.shadow.css';
|
|
8
|
-
import type {
|
|
9
|
-
import { AbstractButton } from '../AbstractButton/AbstractButton';
|
|
6
|
+
import type { ButtonLinkComponent, ButtonLinkProps } from './ButtonLink.type';
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
resolveColor: resolveColorEnhance(),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class RootButtonLink extends AbstractButton {
|
|
8
|
+
class RootButtonLink extends Component<ButtonLinkProps> {
|
|
16
9
|
static displayName = 'ButtonLink';
|
|
17
|
-
static enhance = Object.values(enhance);
|
|
18
10
|
static style = style;
|
|
19
11
|
static defaultProps = {
|
|
20
12
|
use: 'primary',
|
|
13
|
+
size: 200,
|
|
21
14
|
};
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function LinkText(props: ButtonLinkTextProps) {
|
|
30
|
-
const SText = Root;
|
|
31
|
-
return sstyled(props.styles)(<SText render={Text} />);
|
|
32
|
-
}
|
|
16
|
+
render(): React.ReactNode {
|
|
17
|
+
const SButtonLink = Root;
|
|
18
|
+
const { disabled } = this.asProps;
|
|
33
19
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
return sstyled(style)(
|
|
21
|
+
<SButtonLink
|
|
22
|
+
render={Link}
|
|
23
|
+
tag='button'
|
|
24
|
+
type='button'
|
|
25
|
+
use:disabled={disabled}
|
|
26
|
+
use:tabIndex={0}
|
|
27
|
+
/>,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
37
30
|
}
|
|
38
31
|
|
|
39
32
|
export const ButtonLink = createComponent(RootButtonLink, {
|
|
40
|
-
Text:
|
|
41
|
-
Addon,
|
|
33
|
+
Text: Link.Text,
|
|
34
|
+
Addon: Link.Addon,
|
|
35
|
+
}, {
|
|
36
|
+
parent: Link,
|
|
42
37
|
}) as ButtonLinkComponent;
|
|
@@ -1,29 +1,21 @@
|
|
|
1
|
+
import type { BoxProps } from '@semcore/base-components';
|
|
1
2
|
import type { Intergalactic } from '@semcore/core';
|
|
3
|
+
import type { LinkProps } from '@semcore/link';
|
|
4
|
+
import type { TextProps } from '@semcore/typography';
|
|
2
5
|
|
|
3
|
-
import type {
|
|
4
|
-
AbstractButtonAddonProps,
|
|
5
|
-
AbstractButtonContext,
|
|
6
|
-
AbstractButtonTextProps,
|
|
7
|
-
AbstractButtonProps,
|
|
8
|
-
} from '../AbstractButton/AbstractButton.type';
|
|
6
|
+
import type { ButtonContext } from '../Button/Button.type';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
type Use = 'primary' | 'secondary';
|
|
19
|
-
|
|
20
|
-
export type ButtonLinkProps = AbstractButtonProps<ButtonLinkSize, Use, never>;
|
|
21
|
-
|
|
22
|
-
export type ButtonLinkTextProps = AbstractButtonTextProps<ButtonLinkSize>;
|
|
8
|
+
export type ButtonLinkProps = Intergalactic.InternalTypings.EfficientOmit<LinkProps, 'enableVisited'> & {
|
|
9
|
+
/**
|
|
10
|
+
* Button link type
|
|
11
|
+
* @default primary
|
|
12
|
+
*/
|
|
13
|
+
use?: 'primary' | 'secondary';
|
|
14
|
+
};
|
|
23
15
|
|
|
24
|
-
export type
|
|
16
|
+
export type ButtonLinkTextProps = TextProps;
|
|
25
17
|
|
|
26
|
-
export type
|
|
18
|
+
export type ButtonLinkAddonProps = BoxProps;
|
|
27
19
|
|
|
28
20
|
export type ButtonLinkChildren = {
|
|
29
21
|
Text: Intergalactic.Component<'span', ButtonLinkTextProps>;
|
|
@@ -33,5 +25,5 @@ export type ButtonLinkChildren = {
|
|
|
33
25
|
export type ButtonLinkComponent = Intergalactic.Component<
|
|
34
26
|
'button',
|
|
35
27
|
ButtonLinkProps,
|
|
36
|
-
|
|
28
|
+
ButtonContext
|
|
37
29
|
> & ButtonLinkChildren;
|
|
@@ -1,59 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
SButtonLink {
|
|
2
|
+
border: none;
|
|
3
3
|
font-family: inherit;
|
|
4
|
-
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
SButtonLink[use='primary']:not([color]) {
|
|
5
7
|
color: var(--intergalactic-text-link, #006dca);
|
|
6
|
-
line-height: normal;
|
|
7
|
-
position: relative;
|
|
8
|
-
cursor: pointer;
|
|
9
|
-
text-decoration: none;
|
|
10
|
-
border: none;
|
|
11
|
-
padding: 0;
|
|
12
|
-
margin: 0;
|
|
13
|
-
box-shadow: none;
|
|
14
|
-
-webkit-tap-highlight-color: transparent;
|
|
15
|
-
background: none;
|
|
16
|
-
transition: color 0.15s ease-in-out;
|
|
17
8
|
|
|
9
|
+
&[active],
|
|
18
10
|
&:active,
|
|
19
11
|
&:hover {
|
|
20
|
-
text-decoration: none;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
&::-moz-focus-inner {
|
|
24
|
-
border: none;
|
|
25
|
-
padding: 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
&[active],
|
|
29
|
-
&:hover,
|
|
30
|
-
&:active {
|
|
31
12
|
color: var(--intergalactic-text-link-hover-active, #044792);
|
|
32
|
-
|
|
33
|
-
& SText {
|
|
34
|
-
box-shadow: 0 1px 0 0 currentColor;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
&[enableVisited]:visited,
|
|
39
|
-
&[enableVisited]:visited:hover {
|
|
40
|
-
color: var(--intergalactic-text-link-visited, #8649e1);
|
|
41
13
|
}
|
|
42
|
-
|
|
43
|
-
SText {
|
|
44
|
-
box-shadow: 0 1px 0 0 transparent;
|
|
45
|
-
transition: box-shadow 0.15s ease-in-out;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
SButton[disabled] {
|
|
50
|
-
opacity: var(--intergalactic-disabled-opacity, 0.3);
|
|
51
|
-
cursor: default;
|
|
52
|
-
/* Disable link interactions */
|
|
53
|
-
pointer-events: none;
|
|
54
14
|
}
|
|
55
15
|
|
|
56
|
-
|
|
16
|
+
SButtonLink[use='secondary']:not([color]) {
|
|
57
17
|
color: var(--intergalactic-text-hint, #6c6e79);
|
|
58
18
|
|
|
59
19
|
&[active],
|
|
@@ -61,99 +21,9 @@ SButton[use='secondary'] {
|
|
|
61
21
|
&:hover {
|
|
62
22
|
color: var(--intergalactic-text-hint-hover-active, #484a54);
|
|
63
23
|
}
|
|
64
|
-
|
|
65
|
-
SText {
|
|
66
|
-
box-shadow: none;
|
|
67
|
-
border-bottom-width: 1px;
|
|
68
|
-
border-bottom-style: dashed;
|
|
69
|
-
border-color: currentColor;
|
|
70
|
-
}
|
|
71
24
|
}
|
|
72
25
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
justify-content: center;
|
|
77
|
-
height: 100%;
|
|
78
|
-
width: 100%;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
SAddon {
|
|
82
|
-
display: inline-flex;
|
|
83
|
-
justify-content: center;
|
|
84
|
-
align-items: baseline;
|
|
85
|
-
vertical-align: middle;
|
|
86
|
-
pointer-events: none;
|
|
87
|
-
align-self: center;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
SButton SAddon {
|
|
91
|
-
&:not(:only-child):first-child {
|
|
92
|
-
margin-right: var(--intergalactic-spacing-1x, 4px);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
&:not(:only-child):last-child {
|
|
96
|
-
margin-left: var(--intergalactic-spacing-1x, 4px);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
SButton[text-color] {
|
|
101
|
-
color: var(--text-color);
|
|
102
|
-
|
|
103
|
-
&[active],
|
|
104
|
-
&:hover,
|
|
105
|
-
&:active {
|
|
106
|
-
color: var(--text-color);
|
|
107
|
-
filter: brightness(0.8);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
SButton[size='100'] {
|
|
112
|
-
font-size: var(--intergalactic-fs-100, 12px);
|
|
113
|
-
line-height: var(--intergalactic-lh-100, 133%);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
SButton[size='200'] {
|
|
117
|
-
font-size: var(--intergalactic-fs-200, 14px);
|
|
118
|
-
line-height: var(--intergalactic-lh-200, 142%);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
SButton[size='300'] {
|
|
122
|
-
font-size: var(--intergalactic-fs-300, 16px);
|
|
123
|
-
line-height: var(--intergalactic-lh-300, 150%);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
SButton[size='400'] {
|
|
127
|
-
font-size: var(--intergalactic-fs-400, 20px);
|
|
128
|
-
line-height: var(--intergalactic-lh-400, 120%);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
SButton[size='500'] {
|
|
132
|
-
font-size: var(--intergalactic-fs-500, 24px);
|
|
133
|
-
line-height: var(--intergalactic-lh-500, 117%);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
SButton[size='600'] {
|
|
137
|
-
font-size: var(--intergalactic-fs-600, 32px);
|
|
138
|
-
line-height: var(--intergalactic-lh-600, 125%);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
SButton[size='700'] {
|
|
142
|
-
font-size: var(--intergalactic-fs-700, 36px);
|
|
143
|
-
line-height: var(--intergalactic-lh-700, 110%);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
SButton[size='800'] {
|
|
147
|
-
font-size: var(--intergalactic-fs-800, 48px);
|
|
148
|
-
line-height: var(--intergalactic-lh-800, 117%);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@media (prefers-reduced-motion) {
|
|
152
|
-
SButton {
|
|
153
|
-
transition: none;
|
|
154
|
-
|
|
155
|
-
SText {
|
|
156
|
-
transition: none;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
26
|
+
SButtonLink[use='secondary'] SText {
|
|
27
|
+
text-decoration-style: dashed;
|
|
28
|
+
text-decoration-color: currentColor;
|
|
159
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { default } from './component/Button/Button';
|
|
1
|
+
export { default, MAP_USE_DEFAULT_THEME } from './component/Button/Button';
|
|
2
2
|
export * from './component/Button/Button.type';
|
|
3
3
|
export * from './component/ButtonLink/ButtonLink';
|
|
4
4
|
export * from './component/ButtonLink/ButtonLink.type';
|
|
5
|
-
export { MAP_USE_DEFAULT_THEME } from './component/AbstractButton/AbstractButton';
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.MAP_USE_DEFAULT_THEME = exports.AbstractButton = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _core = require("@semcore/core");
|
|
10
|
-
var _baseComponents = require("@semcore/base-components");
|
|
11
|
-
var _addonTextChildren = _interopRequireDefault(require("@semcore/core/lib/utils/addonTextChildren"));
|
|
12
|
-
var _hasLabels = _interopRequireDefault(require("@semcore/core/lib/utils/hasLabels"));
|
|
13
|
-
var _logger = _interopRequireDefault(require("@semcore/core/lib/utils/logger"));
|
|
14
|
-
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
var _SpinButton = _interopRequireDefault(require("./SpinButton"));
|
|
16
|
-
const MAP_USE_DEFAULT_THEME = exports.MAP_USE_DEFAULT_THEME = {
|
|
17
|
-
primary: 'info',
|
|
18
|
-
secondary: 'muted',
|
|
19
|
-
tertiary: 'info'
|
|
20
|
-
};
|
|
21
|
-
class AbstractButton extends _core.Component {
|
|
22
|
-
constructor(...args) {
|
|
23
|
-
super(...args);
|
|
24
|
-
(0, _defineProperty2.default)(this, "containerRef", /*#__PURE__*/_react.default.createRef());
|
|
25
|
-
(0, _defineProperty2.default)(this, "state", {
|
|
26
|
-
ariaLabelledByContent: null
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
getTextProps(props) {
|
|
30
|
-
const {
|
|
31
|
-
size
|
|
32
|
-
} = this.asProps;
|
|
33
|
-
|
|
34
|
-
// `any` because we don't have typings for `use:PROPS`.
|
|
35
|
-
const textProps = {
|
|
36
|
-
size,
|
|
37
|
-
'use:hintProps': {
|
|
38
|
-
triggerRef: this.containerRef
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
if ('hintProps' in props) {
|
|
42
|
-
textProps['use:hintProps'] = {
|
|
43
|
-
triggerRef: this.containerRef,
|
|
44
|
-
...props.hintProps
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return textProps;
|
|
48
|
-
}
|
|
49
|
-
getAddonProps() {
|
|
50
|
-
const {
|
|
51
|
-
size
|
|
52
|
-
} = this.asProps;
|
|
53
|
-
return {
|
|
54
|
-
size
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
componentDidMount() {
|
|
58
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
59
|
-
_logger.default.warn(this.containerRef.current && !(0, _hasLabels.default)(this.containerRef.current) && !this.asProps.title, `'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`, this.asProps['data-ui-name'] || AbstractButton.displayName);
|
|
60
|
-
_logger.default.warn(this.asProps.theme === 'warning', 'Warning theme is deprecated and will be removed in the next major release.', this.asProps['data-ui-name'] || AbstractButton.displayName);
|
|
61
|
-
}
|
|
62
|
-
const ariaLabelledby = this.asProps['aria-labelledby'];
|
|
63
|
-
if (ariaLabelledby) {
|
|
64
|
-
setTimeout(() => {
|
|
65
|
-
this.setState({
|
|
66
|
-
ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? ''
|
|
67
|
-
});
|
|
68
|
-
}, 0);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
render() {
|
|
72
|
-
var _ref = this.asProps;
|
|
73
|
-
const {
|
|
74
|
-
styles,
|
|
75
|
-
use,
|
|
76
|
-
theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
|
|
77
|
-
loading,
|
|
78
|
-
disabled = loading,
|
|
79
|
-
size,
|
|
80
|
-
neighborLocation,
|
|
81
|
-
children,
|
|
82
|
-
title,
|
|
83
|
-
['aria-label']: ariaLabel,
|
|
84
|
-
Children,
|
|
85
|
-
addonLeft: AddonLeft,
|
|
86
|
-
addonRight: AddonRight,
|
|
87
|
-
hintPlacement
|
|
88
|
-
} = this.asProps;
|
|
89
|
-
const SButton = _baseComponents.Box;
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
const Button = this[_core.CORE_INSTANCE];
|
|
92
|
-
const useTheme = use && theme ? `${use}-${theme}` : false;
|
|
93
|
-
const SInner = _baseComponents.Box;
|
|
94
|
-
const SSpin = _baseComponents.Box;
|
|
95
|
-
const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';
|
|
96
|
-
const showHint = children === undefined || title;
|
|
97
|
-
return /*#__PURE__*/_react.default.createElement(_baseComponents.NeighborLocation.Detect, {
|
|
98
|
-
neighborLocation: neighborLocation
|
|
99
|
-
}, neighborLocation => {
|
|
100
|
-
var _ref2;
|
|
101
|
-
return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(SButton, _ref2.cn("SButton", {
|
|
102
|
-
...(0, _core.assignProps)({
|
|
103
|
-
"invertOutline": theme === 'invert',
|
|
104
|
-
"type": 'button',
|
|
105
|
-
"tag": 'button',
|
|
106
|
-
"tabIndex": 0,
|
|
107
|
-
"disabled": disabled,
|
|
108
|
-
"use:theme": useTheme,
|
|
109
|
-
"ref": this.containerRef,
|
|
110
|
-
"text-color": this.getTextColor(),
|
|
111
|
-
"aria-busy": loading,
|
|
112
|
-
"__excludeProps": ['title'],
|
|
113
|
-
"aria-label": showHint ? buttonAriaLabel : undefined,
|
|
114
|
-
"neighborLocation": neighborLocation
|
|
115
|
-
}, _ref)
|
|
116
|
-
}), /*#__PURE__*/_react.default.createElement(SInner, _ref2.cn("SInner", {
|
|
117
|
-
"tag": 'span',
|
|
118
|
-
"loading": loading,
|
|
119
|
-
"data-ui-name": `${this.asProps['data-ui-name']}.InnerWrapper`
|
|
120
|
-
}), AddonLeft ? /*#__PURE__*/_react.default.createElement(Button.Addon, null, /*#__PURE__*/_react.default.createElement(AddonLeft, _ref2.cn("AddonLeft", {}))) : null, (0, _addonTextChildren.default)(Children, Button.Text, Button.Addon), AddonRight ? /*#__PURE__*/_react.default.createElement(Button.Addon, null, /*#__PURE__*/_react.default.createElement(AddonRight, _ref2.cn("AddonRight", {}))) : null), loading && /*#__PURE__*/_react.default.createElement(SSpin, _ref2.cn("SSpin", {
|
|
121
|
-
"tag": 'span'
|
|
122
|
-
}), /*#__PURE__*/_react.default.createElement(_SpinButton.default, _ref2.cn("SpinButton", {
|
|
123
|
-
"centered": true,
|
|
124
|
-
"size": size,
|
|
125
|
-
"theme": useTheme
|
|
126
|
-
})))), showHint && /*#__PURE__*/_react.default.createElement(_baseComponents.Hint, _ref2.cn("Hint", {
|
|
127
|
-
"triggerRef": this.containerRef,
|
|
128
|
-
"timeout": [250, 50],
|
|
129
|
-
"placement": hintPlacement
|
|
130
|
-
}), buttonAriaLabel));
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.AbstractButton = AbstractButton;
|
|
135
|
-
(0, _defineProperty2.default)(AbstractButton, "displayName", 'AbstractButton');
|
|
136
|
-
//# sourceMappingURL=AbstractButton.js.map
|