@pareto-engineering/design-system 4.0.0-alpha.37 → 4.0.0-alpha.39
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/dist/cjs/f/FormInput/FormInput.js +6 -0
- package/dist/cjs/f/fields/LinkInput/LinkInput.js +164 -0
- package/dist/cjs/f/fields/LinkInput/index.js +13 -0
- package/dist/cjs/f/fields/LinkInput/styles.scss +89 -0
- package/dist/cjs/f/fields/index.js +8 -1
- package/dist/es/f/FormInput/FormInput.js +7 -1
- package/dist/es/f/fields/LinkInput/LinkInput.js +156 -0
- package/dist/es/f/fields/LinkInput/index.js +2 -0
- package/dist/es/f/fields/LinkInput/styles.scss +89 -0
- package/dist/es/f/fields/index.js +2 -1
- package/package.json +3 -3
- package/src/stories/f/LinkInput.stories.jsx +100 -0
- package/src/ui/f/FormInput/FormInput.jsx +12 -0
- package/src/ui/f/fields/LinkInput/LinkInput.jsx +197 -0
- package/src/ui/f/fields/LinkInput/index.js +2 -0
- package/src/ui/f/fields/LinkInput/styles.scss +89 -0
- package/src/ui/f/fields/index.js +1 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +393 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Formik, Form } from 'formik'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
LinkInput,
|
|
7
|
+
FormDebugger,
|
|
8
|
+
} from 'ui'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title :'f/fields/LinkInput',
|
|
12
|
+
component :LinkInput,
|
|
13
|
+
subcomponents:{
|
|
14
|
+
// Item:TextInput.Item
|
|
15
|
+
},
|
|
16
|
+
decorators:[
|
|
17
|
+
(storyfn) => (
|
|
18
|
+
<Formik
|
|
19
|
+
initialValues={{ email: '', name: '', company: '' }}
|
|
20
|
+
>
|
|
21
|
+
<Form>
|
|
22
|
+
|
|
23
|
+
{ storyfn() }
|
|
24
|
+
</Form>
|
|
25
|
+
</Formik>
|
|
26
|
+
),
|
|
27
|
+
],
|
|
28
|
+
argTypes:{
|
|
29
|
+
// backgroundColor:{ control: 'color' },
|
|
30
|
+
placeholder :{ control: 'text' },
|
|
31
|
+
autoComplete :{ control: 'select', options: ['off', 'on'] },
|
|
32
|
+
disabled :{ control: 'boolean' },
|
|
33
|
+
name :{ control: 'text' },
|
|
34
|
+
label :{ control: 'text' },
|
|
35
|
+
labelColor :{ control: 'text' },
|
|
36
|
+
optional :{ control: 'boolean' },
|
|
37
|
+
symbol :{ control: 'text' },
|
|
38
|
+
labelSpan :{ control: 'number' },
|
|
39
|
+
inputSpan :{ control: 'number' },
|
|
40
|
+
desktopLabelSpan:{ control: 'number' },
|
|
41
|
+
desktopInputSpan:{ control: 'number' },
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line react/prop-types
|
|
46
|
+
const Template = (args) => (
|
|
47
|
+
<div className="grid">
|
|
48
|
+
<LinkInput {...args} />
|
|
49
|
+
<FormDebugger />
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
export const Base = Template.bind({})
|
|
54
|
+
Base.args = {
|
|
55
|
+
name :'link',
|
|
56
|
+
label:'Spreadsheet Link',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const Optional = Template.bind({})
|
|
60
|
+
Optional.args = {
|
|
61
|
+
...Base.args,
|
|
62
|
+
optional:true,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const validate = (value) => {
|
|
66
|
+
let errorMessage = ''
|
|
67
|
+
const isValid = value.length > 3
|
|
68
|
+
|
|
69
|
+
if (!isValid) {
|
|
70
|
+
errorMessage = 'Value should be greater than 3 characters'
|
|
71
|
+
}
|
|
72
|
+
return errorMessage
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const WithValidation = Template.bind({})
|
|
76
|
+
WithValidation.args = {
|
|
77
|
+
...Base.args,
|
|
78
|
+
validate,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const WithPlaceholder = Template.bind({})
|
|
82
|
+
WithPlaceholder.args = {
|
|
83
|
+
...Base.args,
|
|
84
|
+
placeholder:'Email address',
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const WithDisabled = Template.bind({})
|
|
88
|
+
WithDisabled.args = {
|
|
89
|
+
...Base.args,
|
|
90
|
+
disabled:true,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const OnSingleRow = Template.bind({})
|
|
94
|
+
OnSingleRow.args = {
|
|
95
|
+
...Base.args,
|
|
96
|
+
labelSpan :4,
|
|
97
|
+
inputSpan :4,
|
|
98
|
+
desktopLabelSpan:4,
|
|
99
|
+
desktopInputSpan:10,
|
|
100
|
+
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
RatingsInput,
|
|
16
16
|
Checkbox,
|
|
17
17
|
QueryChoices,
|
|
18
|
+
LinkInput,
|
|
18
19
|
} from '../fields'
|
|
19
20
|
|
|
20
21
|
// Local Definitions
|
|
@@ -117,6 +118,16 @@ const FormInput = ({
|
|
|
117
118
|
)
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
if (type === 'link') {
|
|
122
|
+
return (
|
|
123
|
+
<LinkInput
|
|
124
|
+
className={newClassName}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
{...otherProps}
|
|
127
|
+
/>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
if (extraTypes?.[type]) {
|
|
121
132
|
const Component = extraTypes[type]
|
|
122
133
|
return (
|
|
@@ -127,6 +138,7 @@ const FormInput = ({
|
|
|
127
138
|
/>
|
|
128
139
|
)
|
|
129
140
|
}
|
|
141
|
+
|
|
130
142
|
return (
|
|
131
143
|
<TextInput
|
|
132
144
|
className={newClassName}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useInsertionEffect, memo } from 'react'
|
|
5
|
+
|
|
6
|
+
import PropTypes from 'prop-types'
|
|
7
|
+
|
|
8
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
9
|
+
|
|
10
|
+
import { useField } from 'formik'
|
|
11
|
+
|
|
12
|
+
import { FormLabel, FormDescription, InputWrapper } from '../../common'
|
|
13
|
+
|
|
14
|
+
// Local Definitions
|
|
15
|
+
|
|
16
|
+
const baseClassName = styleNames.base
|
|
17
|
+
|
|
18
|
+
const componentClassName = 'link-input'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is the component description.
|
|
22
|
+
*/
|
|
23
|
+
const LinkInput = ({
|
|
24
|
+
id,
|
|
25
|
+
className:userClassName,
|
|
26
|
+
style,
|
|
27
|
+
name,
|
|
28
|
+
label,
|
|
29
|
+
color,
|
|
30
|
+
labelColor,
|
|
31
|
+
validate,
|
|
32
|
+
description,
|
|
33
|
+
disabled,
|
|
34
|
+
placeholder,
|
|
35
|
+
optional,
|
|
36
|
+
autoComplete,
|
|
37
|
+
labelSpan,
|
|
38
|
+
desktopLabelSpan,
|
|
39
|
+
inputSpan,
|
|
40
|
+
desktopInputSpan,
|
|
41
|
+
// ...otherProps
|
|
42
|
+
}) => {
|
|
43
|
+
useInsertionEffect(() => {
|
|
44
|
+
import('./styles.scss')
|
|
45
|
+
}, [])
|
|
46
|
+
|
|
47
|
+
const [field] = useField({ name, validate })
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<FormLabel
|
|
52
|
+
name={name}
|
|
53
|
+
color={labelColor}
|
|
54
|
+
optional={optional}
|
|
55
|
+
columnSpan={labelSpan}
|
|
56
|
+
desktopColumnSpan={desktopLabelSpan}
|
|
57
|
+
// {...otherProps}
|
|
58
|
+
>
|
|
59
|
+
{label}
|
|
60
|
+
</FormLabel>
|
|
61
|
+
<InputWrapper
|
|
62
|
+
id={id}
|
|
63
|
+
className={[
|
|
64
|
+
baseClassName,
|
|
65
|
+
componentClassName,
|
|
66
|
+
userClassName,
|
|
67
|
+
`y-${color}`,
|
|
68
|
+
]
|
|
69
|
+
.filter((e) => e)
|
|
70
|
+
.join(' ')}
|
|
71
|
+
style={style}
|
|
72
|
+
columnSpan={inputSpan}
|
|
73
|
+
desktopColumnSpan={desktopInputSpan}
|
|
74
|
+
>
|
|
75
|
+
<div className="input-link-wrapper">
|
|
76
|
+
<input
|
|
77
|
+
id={name}
|
|
78
|
+
className="input"
|
|
79
|
+
type="text"
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
placeholder={placeholder}
|
|
82
|
+
autoComplete={autoComplete}
|
|
83
|
+
{...field}
|
|
84
|
+
/>
|
|
85
|
+
<a
|
|
86
|
+
href={field.value}
|
|
87
|
+
target="_blank"
|
|
88
|
+
rel="noopener noreferrer"
|
|
89
|
+
>
|
|
90
|
+
→
|
|
91
|
+
</a>
|
|
92
|
+
</div>
|
|
93
|
+
<FormDescription className="s-1" description={description} name={name} />
|
|
94
|
+
</InputWrapper>
|
|
95
|
+
</>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
LinkInput.propTypes = {
|
|
100
|
+
/**
|
|
101
|
+
* The HTML id for this element
|
|
102
|
+
*/
|
|
103
|
+
id:PropTypes.string,
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The HTML class names for this element
|
|
107
|
+
*/
|
|
108
|
+
className:PropTypes.string,
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The React-written, css properties for this element.
|
|
112
|
+
*/
|
|
113
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The input name (html - and Formik state)
|
|
117
|
+
*/
|
|
118
|
+
name:PropTypes.string.isRequired,
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The input label
|
|
122
|
+
*/
|
|
123
|
+
label:PropTypes.string.isRequired,
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The input label color
|
|
127
|
+
*/
|
|
128
|
+
labelColor:PropTypes.string,
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The input field validator function
|
|
132
|
+
*/
|
|
133
|
+
validate:PropTypes.func,
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* If the slide will only have one input
|
|
137
|
+
*/
|
|
138
|
+
oneInputLabel:PropTypes.bool,
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Input description
|
|
142
|
+
*/
|
|
143
|
+
description:PropTypes.string,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Whether the text input should be disabled
|
|
147
|
+
*/
|
|
148
|
+
disabled:PropTypes.bool,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The placeholder text for the input
|
|
152
|
+
*/
|
|
153
|
+
placeholder:PropTypes.string,
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The text input color
|
|
157
|
+
*/
|
|
158
|
+
color:PropTypes.string,
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Whether the input is optional or not
|
|
162
|
+
*/
|
|
163
|
+
optional:PropTypes.bool,
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The autoComplete value that the browser should watch for the input
|
|
167
|
+
* `https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete`
|
|
168
|
+
*/
|
|
169
|
+
autoComplete:PropTypes.string,
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The number of columns the label should span
|
|
173
|
+
*/
|
|
174
|
+
labelSpan:PropTypes.number,
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The number of columns the input should span
|
|
178
|
+
*/
|
|
179
|
+
inputSpan:PropTypes.number,
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The number of columns the label should span on desktop
|
|
183
|
+
*/
|
|
184
|
+
desktopLabelSpan:PropTypes.number,
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The number of columns the input should span on desktop
|
|
188
|
+
*/
|
|
189
|
+
desktopInputSpan:PropTypes.number,
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
LinkInput.defaultProps = {
|
|
193
|
+
color :'paragraph',
|
|
194
|
+
disabled:false,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default memo(LinkInput)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
/* stylelint-disable max-nesting-depth -- required here */
|
|
3
|
+
|
|
4
|
+
@use "@pareto-engineering/bem";
|
|
5
|
+
@use "@pareto-engineering/styles/src/mixins";
|
|
6
|
+
@use "@pareto-engineering/styles/src/globals" as *;
|
|
7
|
+
|
|
8
|
+
$default-padding: .55em .75em;
|
|
9
|
+
$default-symbol-left: 1em;
|
|
10
|
+
$default-padding-with-symbol:
|
|
11
|
+
.55em
|
|
12
|
+
calc($default-symbol-left - 1em)
|
|
13
|
+
.55em
|
|
14
|
+
calc($default-symbol-left + 1em);
|
|
15
|
+
$default-input-border-radius: var(--theme-default-input-border-radius);
|
|
16
|
+
$default-border: var(--theme-default-input-border);
|
|
17
|
+
$hover-border: var(--theme-hover-input-border);
|
|
18
|
+
$focus-border: var(--theme-focus-input-border);
|
|
19
|
+
$default-background: var(--background-inputs);
|
|
20
|
+
$disabled-background: var(--background-inputs-30);
|
|
21
|
+
|
|
22
|
+
.#{bem.$base}.link-input {
|
|
23
|
+
&.#{bem.$base}.input-wrapper {
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
position: relative;
|
|
27
|
+
|
|
28
|
+
&.has-symbol {
|
|
29
|
+
&::before {
|
|
30
|
+
color: var(--y);
|
|
31
|
+
content: var(--symbol);
|
|
32
|
+
left: $default-symbol-left;
|
|
33
|
+
position: absolute;
|
|
34
|
+
top: 50%;
|
|
35
|
+
transform: translate(-50%, -50%);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
input {
|
|
39
|
+
padding: $default-padding-with-symbol;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
> .input-link-wrapper {
|
|
44
|
+
display: flex;
|
|
45
|
+
gap: calc(var(--gap) / 2);
|
|
46
|
+
|
|
47
|
+
> a {
|
|
48
|
+
align-self: center;
|
|
49
|
+
border: 1px solid var(--interactive);
|
|
50
|
+
border-radius: var(--theme-default-input-border-radius);
|
|
51
|
+
padding: .5em;
|
|
52
|
+
|
|
53
|
+
&:hover {
|
|
54
|
+
background-color: var(--interactive);
|
|
55
|
+
color: var(--on-interactive);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
> input {
|
|
60
|
+
background-color: $default-background;
|
|
61
|
+
border: $default-border;
|
|
62
|
+
border-radius: $default-input-border-radius;
|
|
63
|
+
color: var(--y);
|
|
64
|
+
outline: none;
|
|
65
|
+
padding: $default-padding;
|
|
66
|
+
width: 100%;
|
|
67
|
+
|
|
68
|
+
&::placeholder {
|
|
69
|
+
color: var(--metadata);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
&:disabled {
|
|
73
|
+
background-color: $disabled-background;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&:not(:disabled) {
|
|
77
|
+
&:hover,
|
|
78
|
+
&:active {
|
|
79
|
+
border: $hover-border;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&:focus {
|
|
83
|
+
border: $focus-border;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/ui/f/fields/index.js
CHANGED