Skip to content

Commit 4f11234

Browse files
connor-baersirineJ
andauthored
New DateInput component (#2645)
Co-authored-by: sirineJ <[email protected]>
1 parent f601c09 commit 4f11234

39 files changed

+2823
-117
lines changed

.changeset/chilly-dodos-end.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@sumup-oss/circuit-ui": major
2+
'@sumup-oss/circuit-ui': major
33
---
44

5-
Upgraded to `@sumup-oss/intl` v2. If your app also depends on `@sumup-oss/intl` (previously called `@sumup/intl`), you need to upgrade it as well.
5+
Upgraded to `@sumup-oss/intl` v3. If your app also depends on `@sumup-oss/intl` (previously called `@sumup/intl`), you need to upgrade it as well.

.changeset/tiny-jars-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sumup-oss/circuit-ui": major
3+
---
4+
5+
Rewrote the DateInput component and replaced the native date input with a custom implementation to improve its usability and accessibility. The component now requires additional localized label props.

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module.exports = require('@sumup-oss/foundry/eslint')({
2323
'@sumup-oss/circuit-ui/no-renamed-props': 'error',
2424
'@sumup-oss/circuit-ui/prefer-custom-properties': 'warn',
2525
'react/no-unknown-property': ['error', { ignore: ['css'] }],
26+
// These rules are already covered by Biome
27+
'jsx-a11y/click-events-have-key-events': 'off',
28+
'jsx-a11y/no-static-element-interactions': 'off',
2629
},
2730
parserOptions: {
2831
project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'],

package-lock.json

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/circuit-ui/components/CurrencyInput/CurrencyInput.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { resolveCurrencyFormat } from '@sumup-oss/intl';
2020
import { NumericFormat, type NumericFormatProps } from 'react-number-format';
2121

2222
import { clsx } from '../../styles/clsx.js';
23+
import { getBrowserLocale, type Locale } from '../../util/i18n.js';
2324
import { Input, type InputProps } from '../Input/index.js';
2425

2526
import { formatPlaceholder } from './CurrencyInputService.js';
@@ -37,10 +38,12 @@ export interface CurrencyInputProps
3738
*/
3839
currency: string;
3940
/**
40-
* One or more Unicode BCP 47 locale identifiers, such as 'de-DE' or
41-
* ['GB', 'en-US'] (the first supported locale is used).
41+
* One or more [IETF BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag)
42+
* locale identifiers such as `'de-DE'` or `['GB', 'en-US']`.
43+
* When passing an array, the first supported locale is used.
44+
* Defaults to `navigator.language` in supported environments.
4245
*/
43-
locale?: string | string[];
46+
locale?: Locale;
4447
/**
4548
* A short string that is shown inside the empty input.
4649
* If the placeholder is a number, it is formatted in the local
@@ -76,7 +79,7 @@ const DUMMY_DELIMITER = '?';
7679
export const CurrencyInput = forwardRef<HTMLInputElement, CurrencyInputProps>(
7780
(
7881
{
79-
locale,
82+
locale = getBrowserLocale(),
8083
currency,
8184
placeholder,
8285
'aria-describedby': descriptionId,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Meta, Status, Props, Story } from '../../../../.storybook/components';
2+
import * as Stories from './DateInput.stories';
3+
4+
<Meta of={Stories} />
5+
6+
# DateInput
7+
8+
<Status variant="stable" />
9+
10+
The DateInput component allows users to type or select a specific date. The input value is always a string in the format `YYYY-MM-DD`.
11+
12+
<Story of={Stories.Base} />
13+
<Props />
14+
15+
## Usage
16+
17+
Use the component whenever asking for a specific individual date such as a birth date, expiry date, or appointment date. The date is in the [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format (`YYYY-MM-DD`).
18+
19+
For selecting a range of dates, we expect to introduce an iteration of this component in the future. Until then, we recommend using a combination of two input fields (one for the start and the other for the end date).
20+
21+
## Validations
22+
23+
Use the `validationHint` prop to communicate the expected response to users. The DateInput component ensures that the entered date is a valid date, but does not validate whether it falls within the minimum or maximum date range.
24+
25+
### Invalid
26+
27+
The user needs to change the value to proceed. This could be because they entered a date outside of the allowed range.
28+
29+
### Warning
30+
31+
The user is recommended to change the value, but can proceed without doing so. Use it when the provided value could have unintended side-effects, such as a date in the far future.
32+
33+
### Valid
34+
35+
The user is reassured that the value is valid. Use sparingly.
36+
37+
<Story of={Stories.Validations} />
38+
39+
## Optional
40+
41+
Use the `optionalLabel` prop to indicate that the field is optional. This can help reduce the cognitive load for the user by clearly indicating which fields are required and which are not. This label is only displayed when the `required` prop is falsy.
42+
43+
<Story of={Stories.Optional} />
44+
45+
## Readonly
46+
47+
Use the `readOnly` prop to indicate that the field is not currently editable. This can be useful in situations where the user needs to view but not edit the date, such as in a summary or review screen.
48+
49+
<Story of={Stories.Readonly} />
50+
51+
## Internationalization
52+
53+
Pass one or more [IETF BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag) locale identifiers such as `'de-DE'` or `['GB', 'en-US']` to the `locale` prop to display the date in the local format. When passing an array, the first supported locale is used. Defaults to `navigator.language` in supported environments.
54+
55+
<Story of={Stories.Locales} />

0 commit comments

Comments
 (0)