agroptima-design-system 0.26.9 → 0.26.10
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/atoms/Input.scss +6 -0
- package/src/atoms/Input.tsx +11 -2
- package/src/stories/Changelog.mdx +4 -0
- package/tests/Input.spec.tsx +14 -1
package/package.json
CHANGED
package/src/atoms/Input.scss
CHANGED
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
|
|
16
16
|
.input-label {
|
|
17
17
|
@include typography.form-label;
|
|
18
|
+
|
|
19
|
+
&.is-required::after {
|
|
20
|
+
content: '*';
|
|
21
|
+
color: color_alias.$primary-color-600;
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
&.invalid .input-help-text {
|
|
@@ -146,4 +151,5 @@
|
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
153
|
}
|
|
154
|
+
|
|
149
155
|
}
|
package/src/atoms/Input.tsx
CHANGED
|
@@ -18,6 +18,7 @@ export interface InputProps extends React.ComponentPropsWithoutRef<'input'> {
|
|
|
18
18
|
id?: string
|
|
19
19
|
suffix?: string
|
|
20
20
|
errors?: string[]
|
|
21
|
+
required?: boolean
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export function Input({
|
|
@@ -34,6 +35,7 @@ export function Input({
|
|
|
34
35
|
name,
|
|
35
36
|
id,
|
|
36
37
|
errors,
|
|
38
|
+
required = false,
|
|
37
39
|
...props
|
|
38
40
|
}: InputProps): React.JSX.Element {
|
|
39
41
|
const identifier = id || name
|
|
@@ -62,10 +64,14 @@ export function Input({
|
|
|
62
64
|
})}
|
|
63
65
|
>
|
|
64
66
|
{!hideLabel && (
|
|
65
|
-
<label
|
|
67
|
+
<label
|
|
68
|
+
className={classNames('input-label', required ? 'is-required' : '')}
|
|
69
|
+
htmlFor={identifier}
|
|
70
|
+
>
|
|
66
71
|
{label}
|
|
67
72
|
</label>
|
|
68
73
|
)}
|
|
74
|
+
|
|
69
75
|
<div className="input-container">
|
|
70
76
|
{icon && <Icon className="left-icon" name={icon} />}
|
|
71
77
|
<input
|
|
@@ -74,7 +80,10 @@ export function Input({
|
|
|
74
80
|
type={handleInputType()}
|
|
75
81
|
name={name}
|
|
76
82
|
aria-label={accessibilityLabel || label}
|
|
77
|
-
|
|
83
|
+
required={required}
|
|
84
|
+
className={classNames({
|
|
85
|
+
'primary-outlined': type === 'file',
|
|
86
|
+
})}
|
|
78
87
|
{...props}
|
|
79
88
|
/>
|
|
80
89
|
{suffix && <span className="input-suffix">{suffix}</span>}
|
package/tests/Input.spec.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import { getByText, render, screen } from '@testing-library/react'
|
|
3
3
|
import userEvent from '@testing-library/user-event'
|
|
4
4
|
import { Input } from '@/atoms/Input'
|
|
5
5
|
|
|
@@ -87,4 +87,17 @@ describe('Input', () => {
|
|
|
87
87
|
expect(getByRole('spinbutton')).toBeInTheDocument()
|
|
88
88
|
expect(getByText('€/Bottle')).toBeInTheDocument()
|
|
89
89
|
})
|
|
90
|
+
it('renders required input', () => {
|
|
91
|
+
const { getByText } = render(
|
|
92
|
+
<Input
|
|
93
|
+
helpText="This text can help you"
|
|
94
|
+
label="Required input"
|
|
95
|
+
name="input"
|
|
96
|
+
type="text"
|
|
97
|
+
required
|
|
98
|
+
/>,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
expect(getByText('Required input')).toHaveClass('input-label is-required')
|
|
102
|
+
})
|
|
90
103
|
})
|