@platformatic/ui-components 0.1.149 → 0.1.150
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/.github/workflows/ci.yml +1 -1
- package/.nvmrc +1 -1
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/components/ButtonOnlyIcon.jsx +165 -0
- package/src/stories/ButtonOnlyIcon.stories.jsx +75 -0
package/.github/workflows/ci.yml
CHANGED
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
18.
|
|
1
|
+
18.19.0
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import BorderedBox from './src/components/BorderedBox'
|
|
|
4
4
|
import Box from './src/components/Box'
|
|
5
5
|
import Button from './src/components/Button'
|
|
6
6
|
import ButtonFullRounded from './src/components/ButtonFullRounded'
|
|
7
|
+
import ButtonOnlyIcon from './src/components/ButtonOnlyIcon'
|
|
7
8
|
import Backgrounds from './src/components/backgrounds'
|
|
8
9
|
import CopyAndPaste from './src/components/CopyAndPaste'
|
|
9
10
|
import Checkbox from './src/components/Checkbox'
|
|
@@ -49,6 +50,7 @@ export {
|
|
|
49
50
|
Box,
|
|
50
51
|
Button,
|
|
51
52
|
ButtonFullRounded,
|
|
53
|
+
ButtonOnlyIcon,
|
|
52
54
|
Checkbox,
|
|
53
55
|
CopyAndPaste,
|
|
54
56
|
DetailedMetric,
|
package/package.json
CHANGED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
import React, { useEffect, useState } from 'react'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import styles from './Button.module.css'
|
|
5
|
+
import commonStyles from './Common.module.css'
|
|
6
|
+
import PlatformaticIcon from './PlatformaticIcon'
|
|
7
|
+
import { SIZES, COLORS_BUTTON, BOX_SHADOW, UNDERLINE, HOVER_EFFECTS_BUTTONS, BACKGROUND_COLOR_OPAQUE, MAIN_DARK_BLUE, LARGE, MEDIUM } from './constants'
|
|
8
|
+
|
|
9
|
+
function ButtonOnlyIcon ({
|
|
10
|
+
textClass,
|
|
11
|
+
paddingClass,
|
|
12
|
+
altLabel,
|
|
13
|
+
color,
|
|
14
|
+
backgroundColor,
|
|
15
|
+
size,
|
|
16
|
+
disabled,
|
|
17
|
+
bold,
|
|
18
|
+
hoverEffect,
|
|
19
|
+
bordered,
|
|
20
|
+
fullWidth,
|
|
21
|
+
platformaticIcon,
|
|
22
|
+
platformaticIconAfter,
|
|
23
|
+
selected,
|
|
24
|
+
...rest
|
|
25
|
+
}) {
|
|
26
|
+
let buttonClassName = textClass
|
|
27
|
+
buttonClassName += ` ${styles.button} ${styles['color-' + color]} `
|
|
28
|
+
let contentClassName = `${styles.content} `
|
|
29
|
+
if (paddingClass) {
|
|
30
|
+
contentClassName += `${paddingClass} `
|
|
31
|
+
} else {
|
|
32
|
+
contentClassName += `${styles['button-' + size]} `
|
|
33
|
+
}
|
|
34
|
+
if (disabled) {
|
|
35
|
+
buttonClassName += ' ' + commonStyles[`bordered--${color}-30`]
|
|
36
|
+
contentClassName += ` ${styles.disabled}`
|
|
37
|
+
} else {
|
|
38
|
+
buttonClassName += bordered ? commonStyles[`bordered--${color}-100`] : ''
|
|
39
|
+
}
|
|
40
|
+
if (!bordered) buttonClassName += ` ${styles['no-border']}`
|
|
41
|
+
if (bold) buttonClassName += ` ${styles.fontBold}`
|
|
42
|
+
if (fullWidth) {
|
|
43
|
+
buttonClassName += ` ${styles.fullWidth}`
|
|
44
|
+
}
|
|
45
|
+
if (selected) buttonClassName += ' ' + commonStyles[`selected-background-color-${color}`]
|
|
46
|
+
const [hover, setHover] = useState(false)
|
|
47
|
+
const [backgroundClassName, setBackgroundClassName] = useState(restClassName())
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!disabled) {
|
|
51
|
+
if (hover) {
|
|
52
|
+
switch (hoverEffect) {
|
|
53
|
+
case BACKGROUND_COLOR_OPAQUE:
|
|
54
|
+
setBackgroundClassName(restClassName() + ' ' + commonStyles[`hover-${BACKGROUND_COLOR_OPAQUE}-${color}`])
|
|
55
|
+
break
|
|
56
|
+
case BOX_SHADOW:
|
|
57
|
+
setBackgroundClassName(restClassName() + ' ' + styles[`hover-${BOX_SHADOW}-${backgroundColor}`])
|
|
58
|
+
break
|
|
59
|
+
case UNDERLINE:
|
|
60
|
+
setBackgroundClassName(`${restClassName()} ${styles['underline-effect']}`)
|
|
61
|
+
break
|
|
62
|
+
default:
|
|
63
|
+
break
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
setBackgroundClassName(restClassName())
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [disabled, hover, hoverEffect])
|
|
70
|
+
|
|
71
|
+
function restClassName () {
|
|
72
|
+
return `${commonStyles['background-color-' + backgroundColor]} `
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<button className={`${buttonClassName} ${restClassName()}`} disabled={disabled} alt={altLabel} {...rest} onMouseLeave={() => setHover(false)} onMouseOver={() => setHover(true)}>
|
|
77
|
+
<div className={`${contentClassName} ${backgroundClassName}`}>
|
|
78
|
+
{platformaticIcon ? <PlatformaticIcon key='center' iconName={platformaticIcon.iconName} color={platformaticIcon.color} data-testid='button-icon' size={MEDIUM} onClick={null} disabled={disabled} /> : null}
|
|
79
|
+
</div>
|
|
80
|
+
</button>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
ButtonOnlyIcon.propTypes = {
|
|
85
|
+
/**
|
|
86
|
+
* textClass
|
|
87
|
+
*/
|
|
88
|
+
textClass: PropTypes.string,
|
|
89
|
+
/**
|
|
90
|
+
* paddingClass
|
|
91
|
+
*/
|
|
92
|
+
paddingClass: PropTypes.string,
|
|
93
|
+
/**
|
|
94
|
+
* altLabel
|
|
95
|
+
*/
|
|
96
|
+
altLabel: PropTypes.string,
|
|
97
|
+
/**
|
|
98
|
+
* color of text, icon and borders
|
|
99
|
+
*/
|
|
100
|
+
color: PropTypes.oneOf(COLORS_BUTTON),
|
|
101
|
+
/**
|
|
102
|
+
* background color of the button
|
|
103
|
+
*/
|
|
104
|
+
backgroundColor: PropTypes.oneOf(COLORS_BUTTON),
|
|
105
|
+
/**
|
|
106
|
+
* Size
|
|
107
|
+
*/
|
|
108
|
+
size: PropTypes.oneOf(SIZES),
|
|
109
|
+
/**
|
|
110
|
+
* Disabled
|
|
111
|
+
*/
|
|
112
|
+
disabled: PropTypes.bool,
|
|
113
|
+
/**
|
|
114
|
+
* Bold
|
|
115
|
+
*/
|
|
116
|
+
bold: PropTypes.bool,
|
|
117
|
+
/**
|
|
118
|
+
* Effect on hover
|
|
119
|
+
*/
|
|
120
|
+
hoverEffect: PropTypes.oneOf(HOVER_EFFECTS_BUTTONS),
|
|
121
|
+
/**
|
|
122
|
+
* Apply border: default true
|
|
123
|
+
*/
|
|
124
|
+
bordered: PropTypes.bool,
|
|
125
|
+
/**
|
|
126
|
+
* Full Width: default false
|
|
127
|
+
*/
|
|
128
|
+
fullWidth: PropTypes.bool,
|
|
129
|
+
/**
|
|
130
|
+
* platformaticIcon: should be removed
|
|
131
|
+
*/
|
|
132
|
+
platformaticIcon: PropTypes.shape({
|
|
133
|
+
iconName: PropTypes.string,
|
|
134
|
+
color: PropTypes.string
|
|
135
|
+
}),
|
|
136
|
+
/**
|
|
137
|
+
* platformaticIconAfter: should be removed
|
|
138
|
+
*/
|
|
139
|
+
platformaticIconAfter: PropTypes.shape({
|
|
140
|
+
iconName: PropTypes.string,
|
|
141
|
+
color: PropTypes.string
|
|
142
|
+
}),
|
|
143
|
+
/**
|
|
144
|
+
* Selected: default false
|
|
145
|
+
*/
|
|
146
|
+
selected: PropTypes.bool
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
ButtonOnlyIcon.defaultProps = {
|
|
150
|
+
textClass: '',
|
|
151
|
+
paddingClass: '',
|
|
152
|
+
altLabel: '',
|
|
153
|
+
color: MAIN_DARK_BLUE,
|
|
154
|
+
backgroundColor: 'transparent',
|
|
155
|
+
disabled: false,
|
|
156
|
+
size: LARGE,
|
|
157
|
+
bold: false,
|
|
158
|
+
hoverEffect: BACKGROUND_COLOR_OPAQUE,
|
|
159
|
+
bordered: true,
|
|
160
|
+
fullWidth: false,
|
|
161
|
+
platformaticIcon: null,
|
|
162
|
+
selected: false
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default ButtonOnlyIcon
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import ButtonOnlyIcon from '../components/ButtonOnlyIcon'
|
|
4
|
+
import { COLORS_BUTTON, HOVER_EFFECTS_BUTTONS, SIZES, WHITE, RICH_BLACK, BACKGROUND_COLOR_OPAQUE, SMALL } from '../components/constants'
|
|
5
|
+
|
|
6
|
+
const divStyle = {
|
|
7
|
+
width: '100%',
|
|
8
|
+
height: 'auto',
|
|
9
|
+
padding: '2px',
|
|
10
|
+
backgroundColor: 'white'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
title: 'Platformatic/ButtonOnlyIcon',
|
|
15
|
+
component: ButtonOnlyIcon,
|
|
16
|
+
decorators: [
|
|
17
|
+
(Story) => (
|
|
18
|
+
<div style={divStyle}>
|
|
19
|
+
<Story />
|
|
20
|
+
</div>
|
|
21
|
+
)
|
|
22
|
+
],
|
|
23
|
+
argTypes: {
|
|
24
|
+
altLabel: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
control: 'text'
|
|
27
|
+
},
|
|
28
|
+
bold: {
|
|
29
|
+
type: 'boolean'
|
|
30
|
+
},
|
|
31
|
+
backgroundColor: {
|
|
32
|
+
type: 'radio',
|
|
33
|
+
options: COLORS_BUTTON
|
|
34
|
+
},
|
|
35
|
+
color: {
|
|
36
|
+
type: 'radio',
|
|
37
|
+
options: COLORS_BUTTON
|
|
38
|
+
},
|
|
39
|
+
disabled: {
|
|
40
|
+
type: 'boolean'
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
control: {
|
|
45
|
+
type: 'radio',
|
|
46
|
+
options: SIZES
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
hoverEffect: {
|
|
50
|
+
type: 'radio',
|
|
51
|
+
options: HOVER_EFFECTS_BUTTONS
|
|
52
|
+
},
|
|
53
|
+
bordered: {
|
|
54
|
+
type: 'boolean'
|
|
55
|
+
},
|
|
56
|
+
fullWidth: {
|
|
57
|
+
type: 'boolean'
|
|
58
|
+
},
|
|
59
|
+
selected: {
|
|
60
|
+
type: 'boolean'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const OnlyIconTemplate = (args) => (<ButtonOnlyIcon {...args} />)
|
|
66
|
+
|
|
67
|
+
export const OnlyIcon = OnlyIconTemplate.bind({})
|
|
68
|
+
|
|
69
|
+
OnlyIcon.args = {
|
|
70
|
+
color: WHITE,
|
|
71
|
+
backgroundColor: RICH_BLACK,
|
|
72
|
+
onClick: () => { alert('hit!') },
|
|
73
|
+
hoverEffect: BACKGROUND_COLOR_OPAQUE,
|
|
74
|
+
platformaticIcon: { size: SMALL, iconName: 'RunningIcon', color: WHITE }
|
|
75
|
+
}
|