@platformatic/ui-components 0.19.1 → 0.19.3
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/package.json +1 -1
- package/src/components/Button.jsx +6 -2
- package/src/components/Button.module.css +4 -1
- package/src/components/LoadingSpinner.jsx +2 -2
- package/src/components/loaders/SpinnerCircularV2.jsx +31 -0
- package/src/components/loaders/SpinnerCircularV2.module.css +34 -0
- package/src/stories/Button.stories.jsx +26 -1
package/package.json
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
ACTIVE_AND_INACTIVE_STATUS,
|
|
13
13
|
TRANSPARENT
|
|
14
14
|
} from './constants'
|
|
15
|
-
|
|
15
|
+
import SpinnerCircularV2 from './loaders/SpinnerCircularV2'
|
|
16
|
+
|
|
16
17
|
function Button ({
|
|
17
18
|
textClass = '',
|
|
18
19
|
paddingClass = '',
|
|
@@ -28,6 +29,7 @@ function Button ({
|
|
|
28
29
|
platformaticIcon = null,
|
|
29
30
|
platformaticIconAfter = null,
|
|
30
31
|
selected = false,
|
|
32
|
+
loading = false,
|
|
31
33
|
...rest
|
|
32
34
|
}) {
|
|
33
35
|
let buttonClassName = textClass
|
|
@@ -39,7 +41,7 @@ function Button ({
|
|
|
39
41
|
} else {
|
|
40
42
|
contentClassName += `${styles['button-' + size]} `
|
|
41
43
|
}
|
|
42
|
-
if (disabled) {
|
|
44
|
+
if (disabled || loading) {
|
|
43
45
|
tmpBorderedClassName = commonStyles[`bordered--${color}-30`]
|
|
44
46
|
buttonClassName += ` ${styles.disabled}`
|
|
45
47
|
} else {
|
|
@@ -109,6 +111,8 @@ function Button ({
|
|
|
109
111
|
return (
|
|
110
112
|
<button className={`${buttonClassName} ${restClassName()} ${borderedClassName}`} disabled={disabled} alt={label} {...rest} onMouseLeave={() => setHover(false)} onMouseOver={() => setHover(true)}>
|
|
111
113
|
<div className={`${contentClassName} ${backgroundClassName}`}>
|
|
114
|
+
{loading ? <SpinnerCircularV2 className={styles.spinner} size={28} thickness={1} color={color} /> : null}
|
|
115
|
+
|
|
112
116
|
{platformaticIcon ? <PlatformaticIcon key='left' iconName={platformaticIcon.iconName} color={platformaticIcon.color} data-testid='button-icon' onClick={null} inactive={inactive} /> : null}
|
|
113
117
|
<span className={styles.label}>{label}</span>
|
|
114
118
|
{platformaticIconAfter ? <PlatformaticIcon key='right' iconName={platformaticIconAfter.iconName} color={platformaticIconAfter.color} data-testid='button-icon' onClick={null} inactive={inactive} /> : null}
|
|
@@ -2,13 +2,13 @@ import React from 'react'
|
|
|
2
2
|
import styles from './LoadingSpinner.module.css'
|
|
3
3
|
import SpinnerCircular from './loaders/SpinnerCircular'
|
|
4
4
|
|
|
5
|
-
function LoadingSpinner ({ loading = false }) {
|
|
5
|
+
function LoadingSpinner ({ loading = false, size = 60 }) {
|
|
6
6
|
// If null then loading not started, if true then loading, if false then done loading
|
|
7
7
|
return loading
|
|
8
8
|
? (
|
|
9
9
|
<div className={styles.container} data-testid='loading-spinner'>
|
|
10
10
|
<div data-testid='loading-spinner-content' className={styles.relative}>
|
|
11
|
-
<SpinnerCircular className={styles.spinner} size={
|
|
11
|
+
<SpinnerCircular className={styles.spinner} size={size} />
|
|
12
12
|
</div>
|
|
13
13
|
</div>
|
|
14
14
|
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// https://loading.io/css/
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import styles from './SpinnerCircularV2.module.css'
|
|
4
|
+
import { WHITE } from '../constants'
|
|
5
|
+
|
|
6
|
+
function SpinnerCircular ({
|
|
7
|
+
className = '',
|
|
8
|
+
color = WHITE,
|
|
9
|
+
size = 60,
|
|
10
|
+
thickness = 4
|
|
11
|
+
}) {
|
|
12
|
+
const styleRing = { width: `${size / 4}px`, height: `${size / 4}px` }
|
|
13
|
+
const styleDiv = {
|
|
14
|
+
width: `${size - 16}px`,
|
|
15
|
+
height: `${size - 16}px`,
|
|
16
|
+
margin: `${thickness}px`,
|
|
17
|
+
borderWidth: `${thickness}px`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const spinnerClassName = styles[`ring${color}`] + ` ${styles.ring} ${className}`
|
|
21
|
+
return (
|
|
22
|
+
<div className={spinnerClassName} style={styleRing}>
|
|
23
|
+
<div style={styleDiv} />
|
|
24
|
+
<div style={styleDiv} />
|
|
25
|
+
<div style={styleDiv} />
|
|
26
|
+
<div style={styleDiv} />
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default SpinnerCircular
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.ringwhite {
|
|
2
|
+
color: white;
|
|
3
|
+
}
|
|
4
|
+
.ring,
|
|
5
|
+
.ring div {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
.ring div {
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
display: block;
|
|
11
|
+
position: absolute;
|
|
12
|
+
border-style: solid;
|
|
13
|
+
border-color: currentColor;
|
|
14
|
+
border-radius: 50%;
|
|
15
|
+
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
16
|
+
border-color: currentColor transparent transparent transparent;
|
|
17
|
+
}
|
|
18
|
+
.ring div:nth-child(1) {
|
|
19
|
+
animation-delay: -0.45s;
|
|
20
|
+
}
|
|
21
|
+
.ring div:nth-child(2) {
|
|
22
|
+
animation-delay: -0.3s;
|
|
23
|
+
}
|
|
24
|
+
.ring div:nth-child(3) {
|
|
25
|
+
animation-delay: -0.15s;
|
|
26
|
+
}
|
|
27
|
+
@keyframes lds-ring {
|
|
28
|
+
0% {
|
|
29
|
+
transform: rotate(0deg);
|
|
30
|
+
}
|
|
31
|
+
100% {
|
|
32
|
+
transform: rotate(360deg);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
2
|
import Button from '../components/Button'
|
|
3
3
|
import {
|
|
4
4
|
ALTERNATE_RICH_BLACK,
|
|
@@ -670,3 +670,28 @@ export const FigmaTemplate = DesignSystem.bind({})
|
|
|
670
670
|
FigmaTemplate.args = {
|
|
671
671
|
label: 'Sample label'
|
|
672
672
|
}
|
|
673
|
+
|
|
674
|
+
export const LoadingButton = Template.bind({})
|
|
675
|
+
LoadingButton.args = {
|
|
676
|
+
label: 'Loading Button',
|
|
677
|
+
loading: true
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export const ClickToLoad = (args) => {
|
|
681
|
+
const [loading, setLoading] = useState(false)
|
|
682
|
+
return (
|
|
683
|
+
<Button
|
|
684
|
+
label='Click to Load'
|
|
685
|
+
loading={loading}
|
|
686
|
+
onClick={() => {
|
|
687
|
+
setLoading(true)
|
|
688
|
+
setTimeout(() => setLoading(false), 2000)
|
|
689
|
+
}}
|
|
690
|
+
/>
|
|
691
|
+
)
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
ClickToLoad.args = {
|
|
695
|
+
label: 'Click to Load',
|
|
696
|
+
loading: false
|
|
697
|
+
}
|