@transferwise/components 0.0.0-experimental-333df2c → 0.0.0-experimental-e4e09f5
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/build/dateLookup/dateTrigger/DateTrigger.js +8 -4
- package/build/dateLookup/dateTrigger/DateTrigger.js.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.mjs +8 -4
- package/build/dateLookup/dateTrigger/DateTrigger.mjs.map +1 -1
- package/build/field/Field.js +9 -2
- package/build/field/Field.js.map +1 -1
- package/build/field/Field.mjs +9 -2
- package/build/field/Field.mjs.map +1 -1
- package/build/i18n/en.json +3 -1
- package/build/i18n/en.json.js +3 -1
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +3 -1
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/inputs/SelectInput.js +34 -86
- package/build/inputs/SelectInput.js.map +1 -1
- package/build/inputs/SelectInput.mjs +36 -88
- package/build/inputs/SelectInput.mjs.map +1 -1
- package/build/label/Label.js +29 -1
- package/build/label/Label.js.map +1 -1
- package/build/label/Label.messages.js +15 -0
- package/build/label/Label.messages.js.map +1 -0
- package/build/label/Label.messages.mjs +13 -0
- package/build/label/Label.messages.mjs.map +1 -0
- package/build/label/Label.mjs +30 -2
- package/build/label/Label.mjs.map +1 -1
- package/build/main.css +0 -18
- package/build/styles/dateLookup/dateTrigger/DateTrigger.css +0 -8
- package/build/styles/inputs/SelectInput.css +0 -10
- package/build/styles/main.css +0 -18
- package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
- package/build/types/field/Field.d.ts +4 -2
- package/build/types/field/Field.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/label/Label.d.ts +10 -1
- package/build/types/label/Label.d.ts.map +1 -1
- package/build/types/label/Label.messages.d.ts +12 -0
- package/build/types/label/Label.messages.d.ts.map +1 -0
- package/build/types/label/index.d.ts +3 -0
- package/build/types/label/index.d.ts.map +1 -0
- package/package.json +4 -5
- package/src/dateInput/DateInput.tests.story.tsx +8 -32
- package/src/dateLookup/DateLookup.rtl.spec.tsx +1 -1
- package/src/dateLookup/dateTrigger/DateTrigger.css +0 -8
- package/src/dateLookup/dateTrigger/DateTrigger.less +0 -8
- package/src/dateLookup/dateTrigger/DateTrigger.spec.js +1 -1
- package/src/dateLookup/dateTrigger/DateTrigger.tsx +9 -4
- package/src/field/Field.spec.tsx +3 -3
- package/src/field/Field.story.tsx +81 -3
- package/src/field/Field.tsx +10 -4
- package/src/i18n/en.json +3 -1
- package/src/index.ts +1 -1
- package/src/inlineAlert/InlineAlert.story.tsx +8 -21
- package/src/inputs/InputGroup.spec.tsx +1 -1
- package/src/inputs/SearchInput.spec.tsx +1 -1
- package/src/inputs/SelectInput.css +0 -10
- package/src/inputs/SelectInput.less +0 -12
- package/src/inputs/SelectInput.spec.tsx +1 -1
- package/src/inputs/SelectInput.story.tsx +0 -20
- package/src/inputs/SelectInput.tsx +37 -116
- package/src/label/Label.messages.tsx +12 -0
- package/src/label/Label.story.tsx +30 -21
- package/src/label/Label.tsx +43 -2
- package/src/label/index.ts +2 -0
- package/src/main.css +0 -18
- package/src/radioGroup/RadioGroup.rtl.spec.tsx +1 -1
- package/src/select/Select.rtl.spec.tsx +1 -1
- package/src/switch/Switch.spec.tsx +1 -1
- package/src/field/Field.tests.story.tsx +0 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectInput.d.ts","sourceRoot":"","sources":["../../../src/inputs/SelectInput.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SelectInput.d.ts","sourceRoot":"","sources":["../../../src/inputs/SelectInput.tsx"],"names":[],"mappings":"AAqBA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKjC,OAAO,EAAsB,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAgC1E,MAAM,W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AA+DD,wBAAgB,WAAW,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK,EAAE,EACjE,EAAE,EAAE,MAAM,EACV,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,KAAK,EACL,YAAY,EACZ,KAAK,EAAE,eAAe,EACtB,aAAa,EACb,WAAoB,EACpB,YAAY,EACZ,aAAoC,EACpC,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,IAAW,EACX,SAAS,EACT,yBAAyB,EACzB,cAAqB,EACrB,QAAQ,EACR,OAAO,EACP,OAAO,GACR,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,+BAoJxB;AAED,KAAK,mCAAmC,GAAG,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC;AAE1E,MAAM,MAAM,6BAA6B,CACvC,CAAC,SAAS,mCAAmC,GAAG,QAAQ,IACtD,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE;IAAE,EAAE,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEzD,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,mCAAmC,GAAG,QAAQ,EAAE,EACjG,EAAkB,EAClB,GAAG,SAAS,EACb,EAAE,6BAA6B,CAAC,CAAC,CAAC,+BAalC;AAyTD,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACxB;AAED,wBAAgB,wBAAwB,CAAC,EACvC,KAAK,EACL,IAAI,EACJ,WAAW,EACX,IAAI,GACL,EAAE,6BAA6B,+BAiD/B"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { CommonProps } from '../common';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
1
3
|
export type LabelProps = {
|
|
2
4
|
id?: string;
|
|
3
5
|
htmlFor?: string;
|
|
4
6
|
className?: string;
|
|
5
7
|
children?: React.ReactNode;
|
|
6
8
|
};
|
|
7
|
-
|
|
9
|
+
declare const Label: {
|
|
10
|
+
({ id, htmlFor, className, children }: LabelProps): import("react").JSX.Element;
|
|
11
|
+
Optional: ({ children, className }: LabelOptionalProps) => import("react").JSX.Element;
|
|
12
|
+
Description: ({ children, className }: LabelDescriptionProps) => import("react").JSX.Element | null;
|
|
13
|
+
};
|
|
14
|
+
export type LabelOptionalProps = PropsWithChildren<CommonProps>;
|
|
15
|
+
export type LabelDescriptionProps = PropsWithChildren<CommonProps>;
|
|
16
|
+
export { Label };
|
|
8
17
|
//# sourceMappingURL=Label.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/label/Label.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/label/Label.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,QAAA,MAAM,KAAK;2CAA0C,UAAU;wCAsBpB,kBAAkB;2CAkBf,qBAAqB;CAtBlE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAkBhE,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAQnE,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Label.messages.d.ts","sourceRoot":"","sources":["../../../src/label/Label.messages.tsx"],"names":[],"mappings":";;;;;;;;;;AAEA,wBASG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/label/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-e4e09f5",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -93,12 +93,12 @@
|
|
|
93
93
|
"rollup-preserve-directives": "^1.1.1",
|
|
94
94
|
"storybook": "^8.2.2",
|
|
95
95
|
"@transferwise/less-config": "3.1.0",
|
|
96
|
-
"@transferwise/neptune-css": "
|
|
96
|
+
"@transferwise/neptune-css": "0.0.0-experimental-e4e09f5",
|
|
97
97
|
"@wise/components-theming": "1.5.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@transferwise/icons": "^3.7.0",
|
|
101
|
-
"@transferwise/neptune-css": "
|
|
101
|
+
"@transferwise/neptune-css": "0.0.0-experimental-e4e09f5",
|
|
102
102
|
"@wise/art": "^2.7.0",
|
|
103
103
|
"@wise/components-theming": "^1.0.0",
|
|
104
104
|
"react": ">=18",
|
|
@@ -125,8 +125,7 @@
|
|
|
125
125
|
"merge-props": "^6.0.0",
|
|
126
126
|
"prop-types": "^15.8.1",
|
|
127
127
|
"react-popper": "^2.3.0",
|
|
128
|
-
"react-transition-group": "^4.4.5"
|
|
129
|
-
"virtua": "^0.33.3"
|
|
128
|
+
"react-transition-group": "^4.4.5"
|
|
130
129
|
},
|
|
131
130
|
"publishConfig": {
|
|
132
131
|
"access": "public"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Meta, StoryObj } from '@storybook/react';
|
|
2
2
|
import { userEvent, within, fn } from '@storybook/test';
|
|
3
3
|
|
|
4
|
-
import { DateInput,
|
|
4
|
+
import { DateInput, Field, InlineAlert, Label } from '..';
|
|
5
5
|
import { lorem10, storyConfig } from '../test-utils';
|
|
6
6
|
|
|
7
7
|
import Provider from '../provider/Provider';
|
|
@@ -39,43 +39,19 @@ export const WithLabel = {
|
|
|
39
39
|
},
|
|
40
40
|
render: (args) => {
|
|
41
41
|
const id1 = 'date-input-group-label-1';
|
|
42
|
-
const label = 'Date of Birth';
|
|
43
42
|
|
|
44
43
|
return (
|
|
45
44
|
<>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<div className="control-label" id={id1}>
|
|
51
|
-
Date of Delivery
|
|
52
|
-
</div>
|
|
53
|
-
<DateInput {...args} aria-labelledby={id1} />
|
|
45
|
+
<Label id={id1}>
|
|
46
|
+
<Label.Optional>Date of Delivery</Label.Optional>
|
|
47
|
+
</Label>
|
|
48
|
+
<DateInput {...args} aria-labelledby={id1} aria-label="" />
|
|
54
49
|
|
|
55
50
|
<br />
|
|
56
51
|
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</Title>
|
|
61
|
-
<div className="control-label">
|
|
62
|
-
{label}{' '}
|
|
63
|
-
<Info aria-label="Fast transfer hint" title="Fast transfer hint" content={lorem10} />
|
|
64
|
-
</div>
|
|
65
|
-
<DateInput {...args} aria-label={label} />
|
|
66
|
-
|
|
67
|
-
<br />
|
|
68
|
-
|
|
69
|
-
<Title type={Typography.TITLE_SUBSECTION}>
|
|
70
|
-
<code>DateInput</code> wrapped in <code>fieldset</code> + using <code>legend</code> as
|
|
71
|
-
label (rare use case)
|
|
72
|
-
</Title>
|
|
73
|
-
<fieldset>
|
|
74
|
-
<legend className="control-label">
|
|
75
|
-
Expiry Date for Credit Card (example of MONTH_YEAR mode)
|
|
76
|
-
</legend>
|
|
77
|
-
<DateInput {...args} mode={DateMode.MONTH_YEAR} />
|
|
78
|
-
</fieldset>
|
|
52
|
+
<Field label="Date of Delivery">
|
|
53
|
+
<DateInput {...args} />
|
|
54
|
+
</Field>
|
|
79
55
|
</>
|
|
80
56
|
);
|
|
81
57
|
},
|
|
@@ -28,7 +28,7 @@ describe('DateLookup', () => {
|
|
|
28
28
|
</Field>,
|
|
29
29
|
);
|
|
30
30
|
// TODO: Replace with `.toHaveAttribute('aria-haspopup')`
|
|
31
|
-
expect(screen.getByLabelText(
|
|
31
|
+
expect(screen.getByLabelText(/Date of birth/)).toHaveTextContent(
|
|
32
32
|
initialValue.getFullYear().toString(),
|
|
33
33
|
);
|
|
34
34
|
});
|
|
@@ -4,18 +4,10 @@
|
|
|
4
4
|
white-space: nowrap;
|
|
5
5
|
width: 100%;
|
|
6
6
|
}
|
|
7
|
-
.np-date-trigger .control-label {
|
|
8
|
-
font-weight: 400;
|
|
9
|
-
font-weight: var(--font-weight-regular);
|
|
10
|
-
}
|
|
11
7
|
.np-theme-personal .np-date-trigger {
|
|
12
8
|
padding-left: 16px;
|
|
13
9
|
padding-left: var(--size-16);
|
|
14
10
|
}
|
|
15
|
-
.np-theme-personal .np-date-trigger .control-label + span {
|
|
16
|
-
font-weight: 400;
|
|
17
|
-
font-weight: var(--font-weight-regular);
|
|
18
|
-
}
|
|
19
11
|
.clear-btn {
|
|
20
12
|
transition: color 0.15s ease-in-out;
|
|
21
13
|
color: #c9cbce;
|
|
@@ -7,16 +7,8 @@
|
|
|
7
7
|
white-space: nowrap;
|
|
8
8
|
width: 100%;
|
|
9
9
|
|
|
10
|
-
.control-label {
|
|
11
|
-
font-weight: var(--font-weight-regular);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
.np-theme-personal & {
|
|
15
11
|
padding-left: var(--size-16);
|
|
16
|
-
|
|
17
|
-
.control-label + span {
|
|
18
|
-
font-weight: var(--font-weight-regular);
|
|
19
|
-
}
|
|
20
12
|
}
|
|
21
13
|
}
|
|
22
14
|
|
|
@@ -119,5 +119,5 @@ describe('DateTrigger', () => {
|
|
|
119
119
|
const button = () => component.find('.np-date-trigger');
|
|
120
120
|
const clearButton = () => component.find('.clear-btn');
|
|
121
121
|
const chevron = () => component.find(Chevron);
|
|
122
|
-
const label = () => component.find('.
|
|
122
|
+
const label = () => component.find('.np-date-trigger-label');
|
|
123
123
|
});
|
|
@@ -2,12 +2,13 @@ import { formatDate } from '@transferwise/formatting';
|
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
3
|
|
|
4
4
|
import Chevron from '../../chevron';
|
|
5
|
-
import { Size, Position, SizeSmall, SizeMedium, SizeLarge } from '../../common';
|
|
5
|
+
import { Size, Position, SizeSmall, SizeMedium, SizeLarge, Typography } from '../../common';
|
|
6
6
|
import { CloseButton } from '../../common/closeButton/CloseButton';
|
|
7
7
|
|
|
8
8
|
import messages from './DateTrigger.messages';
|
|
9
9
|
import { useContext } from 'react';
|
|
10
10
|
import { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';
|
|
11
|
+
import Body from '../../body';
|
|
11
12
|
|
|
12
13
|
interface DateTriggerProps {
|
|
13
14
|
selectedDate: Date | null;
|
|
@@ -45,15 +46,19 @@ const DateTrigger: React.FC<DateTriggerProps> = ({
|
|
|
45
46
|
type="button"
|
|
46
47
|
onClick={onClick}
|
|
47
48
|
>
|
|
48
|
-
{label &&
|
|
49
|
+
{label && (
|
|
50
|
+
<Body as="span" className="np-date-trigger-label m-r-1">
|
|
51
|
+
{label}
|
|
52
|
+
</Body>
|
|
53
|
+
)}
|
|
49
54
|
{selectedDate ? (
|
|
50
|
-
<
|
|
55
|
+
<Body as="span" type={Typography.BODY_LARGE}>
|
|
51
56
|
{formatDate(selectedDate, locale, {
|
|
52
57
|
day: 'numeric',
|
|
53
58
|
month: monthFormat,
|
|
54
59
|
year: 'numeric',
|
|
55
60
|
})}
|
|
56
|
-
</
|
|
61
|
+
</Body>
|
|
57
62
|
) : (
|
|
58
63
|
<span
|
|
59
64
|
className="form-control-placeholder visible-xs-inline visible-sm-inline
|
package/src/field/Field.spec.tsx
CHANGED
|
@@ -14,7 +14,7 @@ describe('Field', () => {
|
|
|
14
14
|
</Field>,
|
|
15
15
|
);
|
|
16
16
|
|
|
17
|
-
expect(screen.getByLabelText(
|
|
17
|
+
expect(screen.getByLabelText(/Phone number/)).toBeInTheDocument();
|
|
18
18
|
expect(screen.getByRole('textbox')).not.toHaveAttribute('aria-describedby');
|
|
19
19
|
});
|
|
20
20
|
|
|
@@ -25,7 +25,7 @@ describe('Field', () => {
|
|
|
25
25
|
</Field>,
|
|
26
26
|
);
|
|
27
27
|
|
|
28
|
-
const textbox = screen.
|
|
28
|
+
const textbox = screen.getByText('This is help text');
|
|
29
29
|
expect(textbox).toBeInTheDocument();
|
|
30
30
|
expect(textbox).not.toBeInvalid();
|
|
31
31
|
});
|
|
@@ -50,7 +50,7 @@ describe('Field', () => {
|
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
expect(screen.getByRole('textbox', { description: 'This is error text' })).toBeInTheDocument();
|
|
53
|
-
expect(screen.
|
|
53
|
+
expect(screen.getByText('This is help text')).toBeInTheDocument();
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
it('avoids triggering button within label inadvertently', async () => {
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/label-has-associated-control */
|
|
1
2
|
import { useState } from 'react';
|
|
2
3
|
|
|
3
4
|
import { Input } from '../inputs/Input';
|
|
4
5
|
import { Field } from './Field';
|
|
5
6
|
import { Sentiment } from '../common';
|
|
7
|
+
import DateInput from '../dateInput';
|
|
8
|
+
import { fn } from '@storybook/test';
|
|
9
|
+
import { lorem10, lorem40 } from '../test-utils';
|
|
10
|
+
import { TextArea } from '../inputs/TextArea';
|
|
11
|
+
import { SearchInput } from '../inputs/SearchInput';
|
|
12
|
+
import Info from '../info';
|
|
6
13
|
|
|
7
14
|
export default {
|
|
8
15
|
component: Field,
|
|
@@ -13,9 +20,51 @@ export default {
|
|
|
13
20
|
export const Basic = () => {
|
|
14
21
|
const [value, setValue] = useState<string | undefined>('This is some text');
|
|
15
22
|
return (
|
|
16
|
-
<
|
|
17
|
-
<
|
|
18
|
-
|
|
23
|
+
<div className="row">
|
|
24
|
+
<div className="col-md-8 col-md-offset-2">
|
|
25
|
+
<Field label="Phone number" required>
|
|
26
|
+
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
27
|
+
</Field>
|
|
28
|
+
<Field label="Phone number">
|
|
29
|
+
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
30
|
+
</Field>
|
|
31
|
+
<Field label="Phone number" description="Please provide you primary phone number">
|
|
32
|
+
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
33
|
+
</Field>
|
|
34
|
+
|
|
35
|
+
<Field label="Date Of Birth">
|
|
36
|
+
<DateInput onChange={fn} />
|
|
37
|
+
</Field>
|
|
38
|
+
|
|
39
|
+
<Field label="Date Of Birth" description={lorem10}>
|
|
40
|
+
<DateInput onChange={fn} />
|
|
41
|
+
</Field>
|
|
42
|
+
|
|
43
|
+
<Field label="Search business">
|
|
44
|
+
<SearchInput />
|
|
45
|
+
</Field>
|
|
46
|
+
|
|
47
|
+
<Field label="Date Of Birth">
|
|
48
|
+
<TextArea />
|
|
49
|
+
</Field>
|
|
50
|
+
|
|
51
|
+
<Field label="Date Of Birth" message={lorem10} sentiment="negative">
|
|
52
|
+
<TextArea />
|
|
53
|
+
</Field>
|
|
54
|
+
|
|
55
|
+
<Field
|
|
56
|
+
label={
|
|
57
|
+
<>
|
|
58
|
+
Date Of Birth <Info content={lorem40} />
|
|
59
|
+
</>
|
|
60
|
+
}
|
|
61
|
+
message={lorem10}
|
|
62
|
+
sentiment="negative"
|
|
63
|
+
>
|
|
64
|
+
<TextArea />
|
|
65
|
+
</Field>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
19
68
|
);
|
|
20
69
|
};
|
|
21
70
|
|
|
@@ -32,6 +81,35 @@ export const WithStatusMessages = () => {
|
|
|
32
81
|
<Field label="Phone number" sentiment={Sentiment.NEGATIVE} message="This is a required field">
|
|
33
82
|
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
34
83
|
</Field>
|
|
84
|
+
|
|
85
|
+
{/* instance with deprecated `hint` prop */}
|
|
86
|
+
<Field
|
|
87
|
+
label="Phone number"
|
|
88
|
+
hint="This is a helpful message"
|
|
89
|
+
sentiment={Sentiment.NEGATIVE}
|
|
90
|
+
message="Validation error, please take a look"
|
|
91
|
+
>
|
|
92
|
+
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
93
|
+
</Field>
|
|
94
|
+
{/* instance with deprecated `error` & `hint` props */}
|
|
95
|
+
<Field
|
|
96
|
+
label="Phone number"
|
|
97
|
+
hint="This is a helpful message"
|
|
98
|
+
error="Validation error, please take a look"
|
|
99
|
+
>
|
|
100
|
+
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
101
|
+
</Field>
|
|
102
|
+
|
|
103
|
+
<Field
|
|
104
|
+
label="Phone number"
|
|
105
|
+
description="This is a helpful message"
|
|
106
|
+
sentiment={Sentiment.NEGATIVE}
|
|
107
|
+
message="Validation error, please take a look"
|
|
108
|
+
>
|
|
109
|
+
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
110
|
+
</Field>
|
|
111
|
+
|
|
112
|
+
{/* instance of info via `message` property, this is rare case (e.g MoneyInput) */}
|
|
35
113
|
<Field label="Phone number" message="This is a helpful message">
|
|
36
114
|
<Input value={value} onChange={({ target }) => setValue(target.value)} />
|
|
37
115
|
</Field>
|
package/src/field/Field.tsx
CHANGED
|
@@ -9,16 +9,18 @@ import {
|
|
|
9
9
|
InputIdContextProvider,
|
|
10
10
|
InputInvalidProvider,
|
|
11
11
|
} from '../inputs/contexts';
|
|
12
|
-
import { Label } from '../label
|
|
12
|
+
import { Label } from '../label';
|
|
13
13
|
|
|
14
14
|
export type FieldProps = {
|
|
15
15
|
/** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */
|
|
16
16
|
id?: string | null;
|
|
17
17
|
/** Should be specified unless the wrapped control has its own labeling mechanism, e.g. `Checkbox`. */
|
|
18
18
|
label?: React.ReactNode;
|
|
19
|
-
|
|
19
|
+
required?: boolean;
|
|
20
|
+
/** @deprecated use `description` prop instead */
|
|
20
21
|
hint?: React.ReactNode;
|
|
21
22
|
message?: React.ReactNode;
|
|
23
|
+
description?: React.ReactNode;
|
|
22
24
|
/** @deprecated use `message` and `type={Sentiment.NEGATIVE}` prop instead */
|
|
23
25
|
error?: React.ReactNode;
|
|
24
26
|
sentiment?: `${Sentiment.NEGATIVE | Sentiment.NEUTRAL | Sentiment.POSITIVE | Sentiment.WARNING}`;
|
|
@@ -29,14 +31,17 @@ export type FieldProps = {
|
|
|
29
31
|
export const Field = ({
|
|
30
32
|
id,
|
|
31
33
|
label,
|
|
34
|
+
required = false,
|
|
32
35
|
message: propMessage,
|
|
36
|
+
hint,
|
|
37
|
+
description = hint,
|
|
33
38
|
sentiment: propType = Sentiment.NEUTRAL,
|
|
34
39
|
className,
|
|
35
40
|
children,
|
|
36
41
|
...props
|
|
37
42
|
}: FieldProps) => {
|
|
38
43
|
const sentiment = props.error ? Sentiment.NEGATIVE : propType;
|
|
39
|
-
const message =
|
|
44
|
+
const message = propMessage || props.error;
|
|
40
45
|
const hasError = sentiment === Sentiment.NEGATIVE;
|
|
41
46
|
|
|
42
47
|
const labelId = useId();
|
|
@@ -65,7 +70,8 @@ export const Field = ({
|
|
|
65
70
|
>
|
|
66
71
|
{label != null ? (
|
|
67
72
|
<Label id={labelId} htmlFor={inputId}>
|
|
68
|
-
{label}
|
|
73
|
+
{required ? label : <Label.Optional>{label}</Label.Optional>}
|
|
74
|
+
{description && <Label.Description>{description}</Label.Description>}
|
|
69
75
|
{children}
|
|
70
76
|
</Label>
|
|
71
77
|
) : (
|
package/src/i18n/en.json
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"neptune.DateLookup.year": "year",
|
|
19
19
|
"neptune.FlowNavigation.back": "back to previous step",
|
|
20
20
|
"neptune.Info.ariaLabel": "More information",
|
|
21
|
+
"neptune.Label.optional": "(Optional)",
|
|
21
22
|
"neptune.Link.opensInNewTab": "(opens in new tab)",
|
|
22
23
|
"neptune.MoneyInput.Select.placeholder": "Select an option...",
|
|
23
24
|
"neptune.PhoneNumberInput.SelectInput.placeholder": "Select an option...",
|
|
@@ -55,5 +56,6 @@
|
|
|
55
56
|
"neptune.UploadItem.uploaded": "Uploaded",
|
|
56
57
|
"neptune.UploadItem.uploadedFile": "Uploaded file",
|
|
57
58
|
"neptune.UploadItem.uploading": "Uploading...",
|
|
58
|
-
"neptune.UploadItem.uploadingFailed": "Uploading failed"
|
|
59
|
+
"neptune.UploadItem.uploadingFailed": "Uploading failed",
|
|
60
|
+
"neptune.aria.Label.optional": "This field is optional"
|
|
59
61
|
}
|
package/src/index.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type {
|
|
|
44
44
|
} from './inputs/SelectInput';
|
|
45
45
|
export type { TextAreaProps } from './inputs/TextArea';
|
|
46
46
|
export type { InstructionsListProps } from './instructionsList';
|
|
47
|
-
export type { LabelProps } from './label/Label';
|
|
47
|
+
export type { LabelProps, LabelOptionalProps, LabelDescriptionProps } from './label/Label';
|
|
48
48
|
export type { LoaderProps } from './loader';
|
|
49
49
|
export type { MarkdownProps } from './markdown';
|
|
50
50
|
export type { ModalProps } from './modal';
|
|
@@ -5,6 +5,8 @@ import { Sentiment } from '../common';
|
|
|
5
5
|
import { Input } from '../inputs/Input';
|
|
6
6
|
|
|
7
7
|
import InlineAlert, { InlineAlertProps } from './InlineAlert';
|
|
8
|
+
import { Label } from '../label';
|
|
9
|
+
import { lorem40 } from '../test-utils';
|
|
8
10
|
|
|
9
11
|
export default {
|
|
10
12
|
component: InlineAlert,
|
|
@@ -66,41 +68,26 @@ export const Basic = () => {
|
|
|
66
68
|
this manually.
|
|
67
69
|
</p>
|
|
68
70
|
<div className={`form-group ${typeClass}`}>
|
|
69
|
-
<
|
|
70
|
-
Toggleable
|
|
71
|
-
</label>
|
|
71
|
+
<Label htmlFor="id0">Toggleable</Label>
|
|
72
72
|
<Input id="id0" value="Neptune is cool" />
|
|
73
73
|
<InlineAlert type={type}>{message}</InlineAlert>
|
|
74
74
|
</div>
|
|
75
75
|
<div className="form-group has-error">
|
|
76
|
-
<
|
|
77
|
-
Negative
|
|
78
|
-
</label>
|
|
76
|
+
<Label htmlFor="id1">Negative</Label>
|
|
79
77
|
<Input id="id1" value="Neptune is cool" />
|
|
80
78
|
<InlineAlert type="negative">{message}</InlineAlert>
|
|
81
79
|
</div>
|
|
82
80
|
<div className="form-group has-success">
|
|
83
|
-
<
|
|
84
|
-
Positive
|
|
85
|
-
</label>
|
|
81
|
+
<Label htmlFor="id2">Positive</Label>
|
|
86
82
|
<Input id="id2" value="Neptune is cool" />
|
|
87
|
-
<InlineAlert type="positive">
|
|
88
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
|
|
89
|
-
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
|
|
90
|
-
ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
|
91
|
-
</InlineAlert>
|
|
83
|
+
<InlineAlert type="positive">{lorem40}</InlineAlert>
|
|
92
84
|
</div>
|
|
93
85
|
<div className="form-group has-neutral">
|
|
94
|
-
<
|
|
95
|
-
Neutral
|
|
96
|
-
</label>
|
|
86
|
+
<Label htmlFor="id3">Neutral</Label>
|
|
97
87
|
<Input id="id3" value="Neptune is cool" />
|
|
98
|
-
<InlineAlert type="neutral">{message}</InlineAlert>
|
|
99
88
|
</div>
|
|
100
89
|
<div className="form-group">
|
|
101
|
-
<label
|
|
102
|
-
No has-* class
|
|
103
|
-
</label>
|
|
90
|
+
<label htmlFor="id4">No has-* class</label>
|
|
104
91
|
<Input id="id4" value="Neptune is cool" />
|
|
105
92
|
<InlineAlert type="negative">{message}</InlineAlert>
|
|
106
93
|
</div>
|
|
@@ -206,10 +206,6 @@
|
|
|
206
206
|
height: auto;
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
.np-select-input-listbox-container--virtualized {
|
|
210
|
-
/* The wrapping element shrinks this as needed */
|
|
211
|
-
height: 100vh;
|
|
212
|
-
}
|
|
213
209
|
.np-select-input-listbox-container--has-group {
|
|
214
210
|
scroll-padding-top: 32px;
|
|
215
211
|
scroll-padding-top: var(--size-32);
|
|
@@ -228,12 +224,6 @@
|
|
|
228
224
|
outline: var(--ring-outline-color) solid var(--ring-outline-width);
|
|
229
225
|
outline-offset: var(--ring-outline-offset);
|
|
230
226
|
}
|
|
231
|
-
.np-select-input-listbox-container--virtualized .np-select-input-listbox {
|
|
232
|
-
/* Adopted from `VList` in virtua: https://github.com/inokawa/virtua/blob/7f6ed5b37df6b480d4ff350f3960067c5b3519d2/src/react/VList.tsx#L113-L116 */
|
|
233
|
-
overflow-y: auto;
|
|
234
|
-
contain: strict;
|
|
235
|
-
height: 100%;
|
|
236
|
-
}
|
|
237
227
|
.np-select-input-separator-item {
|
|
238
228
|
margin: 8px;
|
|
239
229
|
margin: var(--size-8);
|
|
@@ -60,11 +60,6 @@
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
&--virtualized {
|
|
64
|
-
/* The wrapping element shrinks this as needed */
|
|
65
|
-
height: 100vh;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
63
|
&--has-group {
|
|
69
64
|
scroll-padding-top: var(--size-32);
|
|
70
65
|
}
|
|
@@ -76,13 +71,6 @@
|
|
|
76
71
|
|
|
77
72
|
.focus-ring();
|
|
78
73
|
--ring-outline-offset: calc(-1 * var(--ring-outline-width));
|
|
79
|
-
|
|
80
|
-
.np-select-input-listbox-container--virtualized & {
|
|
81
|
-
/* Adopted from `VList` in virtua: https://github.com/inokawa/virtua/blob/7f6ed5b37df6b480d4ff350f3960067c5b3519d2/src/react/VList.tsx#L113-L116 */
|
|
82
|
-
overflow-y: auto;
|
|
83
|
-
contain: strict;
|
|
84
|
-
height: 100%;
|
|
85
|
-
}
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
.np-select-input-separator-item {
|
|
@@ -214,6 +214,6 @@ describe('SelectInput', () => {
|
|
|
214
214
|
<SelectInput items={[{ type: 'option', value: 'USD' }]} value="USD" />
|
|
215
215
|
</Field>,
|
|
216
216
|
);
|
|
217
|
-
expect(screen.getByLabelText(
|
|
217
|
+
expect(screen.getByLabelText(/Currency/)).toHaveAttribute('aria-haspopup');
|
|
218
218
|
});
|
|
219
219
|
});
|
|
@@ -322,26 +322,6 @@ export const Advanced: Story<Month> = {
|
|
|
322
322
|
},
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
-
export const ManyItems: Story<string, true> = {
|
|
326
|
-
args: {
|
|
327
|
-
multiple: true,
|
|
328
|
-
items: Array.from({ length: 1000 }, (_, index) => ({
|
|
329
|
-
type: 'option',
|
|
330
|
-
value: String(index + 1),
|
|
331
|
-
})),
|
|
332
|
-
renderValue: (value, withinTrigger) =>
|
|
333
|
-
withinTrigger ? (
|
|
334
|
-
value
|
|
335
|
-
) : (
|
|
336
|
-
<SelectInputOptionContent
|
|
337
|
-
title={value}
|
|
338
|
-
description={Number(value) % 10 === 0 ? 'Divisible by 10' : undefined}
|
|
339
|
-
/>
|
|
340
|
-
),
|
|
341
|
-
filterable: true,
|
|
342
|
-
},
|
|
343
|
-
};
|
|
344
|
-
|
|
345
325
|
export const WithinDrawer: Story<Currency> = {
|
|
346
326
|
args: CurrenciesArgs,
|
|
347
327
|
decorators: [
|