@platformatic/ui-components 0.1.48 → 0.1.49
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/forms/Input.jsx +20 -27
- package/src/components/forms/Input.module.css +1 -1
- package/src/components/icons/AppIcon.jsx +1 -1
- package/src/components/icons/CopyIcon.jsx +29 -0
- package/src/components/icons/EditIcon.jsx +38 -0
- package/src/components/icons/index.js +2 -0
- package/src/stories/forms/Input.stories.jsx +25 -5
package/package.json
CHANGED
|
@@ -3,19 +3,19 @@ import React from 'react'
|
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
import styles from './Input.module.css'
|
|
5
5
|
import commonStyles from '../Common.module.css'
|
|
6
|
-
import
|
|
6
|
+
import PlatformaticIcon from '../PlatformaticIcon'
|
|
7
7
|
|
|
8
|
-
function Input ({ placeholder, value, name, borderColor, errorMessage, onChange, disabled,
|
|
8
|
+
function Input ({ placeholder, value, name, borderColor, errorMessage, onChange, disabled, beforeIcon, afterIcon }) {
|
|
9
9
|
let className = styles.inputContainer + ' ' + commonStyles[`bordered--${borderColor}`] + ' ' + commonStyles[`text--${borderColor}`] + ' ' + commonStyles.padded
|
|
10
10
|
const showError = errorMessage.length > 0
|
|
11
11
|
if (showError) className += ' ' + commonStyles['bordered--error-red']
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
return (
|
|
14
14
|
<div className={styles.container}>
|
|
15
15
|
<div className={className}>
|
|
16
|
-
{
|
|
16
|
+
{beforeIcon && <PlatformaticIcon iconName={beforeIcon.iconName} classes={styles.beforeInputIcon} size='small' data-testid='before-icon' color={beforeIcon.color} onClick={() => beforeIcon.onClick()} />}
|
|
17
17
|
<input type='text' name={name} value={value} placeholder={placeholder} className={styles.fullWidth} onChange={onChange} disabled={disabled} />
|
|
18
|
-
{
|
|
18
|
+
{afterIcon && <PlatformaticIcon iconName={afterIcon.iconName} color={afterIcon.color} data-testid='after-icon' onClick={null} />}
|
|
19
19
|
</div>
|
|
20
20
|
{showError && <span className={commonStyles['error-message']}>{errorMessage}</span>}
|
|
21
21
|
</div>
|
|
@@ -48,40 +48,33 @@ Input.propTypes = {
|
|
|
48
48
|
*/
|
|
49
49
|
disabled: PropTypes.bool,
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
beforeInputIcon: PropTypes.object,
|
|
54
|
-
/**
|
|
55
|
-
* beforeInputIconColor
|
|
56
|
-
*/
|
|
57
|
-
beforeInputIconColor: PropTypes.oneOf(['error-red', 'main-dark-blue', 'white']),
|
|
58
|
-
/**
|
|
59
|
-
* afterInputIcon
|
|
60
|
-
*/
|
|
61
|
-
afterInputIcon: PropTypes.object,
|
|
62
|
-
/**
|
|
63
|
-
* afterInputIconColor
|
|
51
|
+
* beforeIcon: PlatformaticIcon props
|
|
64
52
|
*/
|
|
65
|
-
|
|
53
|
+
beforeIcon: PropTypes.shape({
|
|
54
|
+
iconName: PropTypes.string,
|
|
55
|
+
color: PropTypes.string,
|
|
56
|
+
onClick: PropTypes.func
|
|
57
|
+
}),
|
|
66
58
|
/**
|
|
67
|
-
*
|
|
59
|
+
* afterIcon: PlatformaticIcon props
|
|
68
60
|
*/
|
|
69
|
-
|
|
61
|
+
afterIcon: PropTypes.shape({
|
|
62
|
+
iconName: PropTypes.string,
|
|
63
|
+
color: PropTypes.string,
|
|
64
|
+
onClick: PropTypes.func
|
|
65
|
+
})
|
|
70
66
|
}
|
|
71
67
|
|
|
72
68
|
Input.defaultProps = {
|
|
73
69
|
placeholder: '',
|
|
74
|
-
value:
|
|
70
|
+
value: '',
|
|
75
71
|
name: '',
|
|
76
72
|
borderColor: 'main-green',
|
|
77
73
|
errorMessage: '',
|
|
78
74
|
onChange: () => {},
|
|
79
75
|
disabled: false,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
afterInputIcon: null,
|
|
83
|
-
onClickBeforeIcon: () => {},
|
|
84
|
-
afterInputIconColor: 'main-dark-blue'
|
|
76
|
+
beforeIcon: null,
|
|
77
|
+
afterIcon: null
|
|
85
78
|
}
|
|
86
79
|
|
|
87
80
|
export default Input
|
|
@@ -6,6 +6,35 @@ const CopyIcon = ({ color = 'green', size = 'normal' }) => {
|
|
|
6
6
|
let icon = <></>
|
|
7
7
|
switch (size) {
|
|
8
8
|
case 'small':
|
|
9
|
+
icon = (
|
|
10
|
+
<svg
|
|
11
|
+
width={16}
|
|
12
|
+
height={16}
|
|
13
|
+
viewBox='0 0 16 16'
|
|
14
|
+
fill='none'
|
|
15
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
16
|
+
className={className}
|
|
17
|
+
>
|
|
18
|
+
<path
|
|
19
|
+
d='M6 13.5V4.94496C6 4.66882 6.22386 4.44496 6.5 4.44496H10.5365C10.6594 4.44496 10.7779 4.49019 10.8696 4.57203L13.833 7.21858C13.9393 7.31345 14 7.4491 14 7.59152V13.5C14 13.7761 13.7761 14 13.5 14H6.5C6.22386 14 6 13.7761 6 13.5Z'
|
|
20
|
+
stroke='none'
|
|
21
|
+
strokeLinecap='round'
|
|
22
|
+
/>
|
|
23
|
+
<path
|
|
24
|
+
d='M10.5 7.78923V4.44496L14 7.78923H10.5Z'
|
|
25
|
+
stroke='none'
|
|
26
|
+
strokeLinecap='round'
|
|
27
|
+
strokeLinejoin='round'
|
|
28
|
+
/>
|
|
29
|
+
<path
|
|
30
|
+
d='M9.5 3.96723L7.36816 2.12196C7.27729 2.0433 7.16112 2.00001 7.04093 2.00001H4.61364H2.5C2.22386 2.00001 2 2.22386 2 2.50001L2.00001 10.6335C2.00001 10.9096 2.22386 11.1335 2.50001 11.1335H5.50001'
|
|
31
|
+
stroke='none'
|
|
32
|
+
strokeLinecap='round'
|
|
33
|
+
/>
|
|
34
|
+
</svg>
|
|
35
|
+
)
|
|
36
|
+
break
|
|
37
|
+
case 'normal':
|
|
9
38
|
icon = (
|
|
10
39
|
<svg
|
|
11
40
|
width={24}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import styles from './Icons.module.css'
|
|
3
|
+
|
|
4
|
+
const EditIcon = ({ color = 'green', size = 'normal' }) => {
|
|
5
|
+
const className = `${styles.noShrinkForFlex} ` + styles[`${color}`]
|
|
6
|
+
let icon = <></>
|
|
7
|
+
switch (size) {
|
|
8
|
+
case 'small':
|
|
9
|
+
icon = (
|
|
10
|
+
<svg width={16} height={16} viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg' className={className}>
|
|
11
|
+
<rect
|
|
12
|
+
x={10.0554}
|
|
13
|
+
y={4.50607}
|
|
14
|
+
width={2.11765}
|
|
15
|
+
height={7.76471}
|
|
16
|
+
transform='rotate(45 10.0554 4.50607)'
|
|
17
|
+
stroke='none'
|
|
18
|
+
strokeLinejoin='round'
|
|
19
|
+
/>
|
|
20
|
+
<path
|
|
21
|
+
d='M6.06234 11.4939L4.56494 9.99654L3.81624 12.2426L6.06234 11.4939Z'
|
|
22
|
+
stroke='none'
|
|
23
|
+
strokeLinejoin='round'
|
|
24
|
+
/>
|
|
25
|
+
<path
|
|
26
|
+
d='M10.8456 3.71577C11.2362 3.32525 11.8693 3.32525 12.2598 3.71577L12.343 3.79896C12.7336 4.18949 12.7336 4.82265 12.343 5.21318L11.5527 6.00347L10.0553 4.50607L10.8456 3.71577Z'
|
|
27
|
+
stroke='none'
|
|
28
|
+
/>
|
|
29
|
+
</svg>
|
|
30
|
+
)
|
|
31
|
+
break
|
|
32
|
+
default:
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
return icon
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default EditIcon
|
|
@@ -16,6 +16,7 @@ import CloseIcon from './CloseIcon'
|
|
|
16
16
|
import CopyIcon from './CopyIcon'
|
|
17
17
|
import CreatedWorkspaceIcon from './CreatedWorkspaceIcon'
|
|
18
18
|
import DynamicWorkspaceIcon from './DynamicWorkspaceIcon'
|
|
19
|
+
import EditIcon from './EditIcon'
|
|
19
20
|
import GearIcon from './GearIcon'
|
|
20
21
|
import LiveIcon from './LiveIcon'
|
|
21
22
|
import MetricsIcon from './MetricsIcon'
|
|
@@ -47,6 +48,7 @@ export default {
|
|
|
47
48
|
CreatedWorkspaceIcon,
|
|
48
49
|
DynamicWorkspaceIcon,
|
|
49
50
|
GearIcon,
|
|
51
|
+
EditIcon,
|
|
50
52
|
LiveIcon,
|
|
51
53
|
MetricsIcon,
|
|
52
54
|
PlayIcon,
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
import React, { useState } from 'react'
|
|
3
3
|
import Input from '../../components/forms/Input'
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
const divStyle = {
|
|
6
|
+
width: '100%',
|
|
7
|
+
height: 'auto',
|
|
8
|
+
padding: '20px',
|
|
9
|
+
backgroundColor: 'white'
|
|
10
|
+
}
|
|
5
11
|
|
|
6
12
|
export default {
|
|
7
13
|
title: 'Platformatic/Forms/Input',
|
|
8
|
-
component: Input
|
|
14
|
+
component: Input,
|
|
15
|
+
decorators: [
|
|
16
|
+
(Story) => (
|
|
17
|
+
<div style={divStyle}>
|
|
18
|
+
<Story />
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
]
|
|
9
22
|
}
|
|
10
23
|
|
|
11
24
|
const Template = (args) => <Input {...args} />
|
|
@@ -63,7 +76,14 @@ export const IconBeforeAndAfter = Template.bind({})
|
|
|
63
76
|
IconBeforeAndAfter.args = {
|
|
64
77
|
name: 'test',
|
|
65
78
|
placeholder: 'Platformatic',
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
beforeIcon: {
|
|
80
|
+
iconName: 'CopyIcon',
|
|
81
|
+
color: 'main-dark-blue',
|
|
82
|
+
size: 'small',
|
|
83
|
+
onClick: () => { alert('clicked') }
|
|
84
|
+
},
|
|
85
|
+
afterIcon: {
|
|
86
|
+
iconName: 'CircleAddIcon',
|
|
87
|
+
color: 'red'
|
|
88
|
+
}
|
|
69
89
|
}
|