From 24484d2c968c408fc65ff1489eed6ab8b7569293 Mon Sep 17 00:00:00 2001 From: Andrey Morozov Date: Wed, 26 Jun 2024 14:26:55 +0300 Subject: [PATCH] feat(PinInput): `responsive` prop and CSS API (#1679) --- src/components/PinInput/PinInput.scss | 15 ++++++++++++--- src/components/PinInput/PinInput.tsx | 4 +++- src/components/PinInput/README.md | 8 ++++++++ .../PinInput/__stories__/PinInput.stories.tsx | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/components/PinInput/PinInput.scss b/src/components/PinInput/PinInput.scss index dd554e23d7..ec9c1aa21f 100644 --- a/src/components/PinInput/PinInput.scss +++ b/src/components/PinInput/PinInput.scss @@ -6,13 +6,13 @@ $block: '.#{variables.$ns}pin-input'; display: inline-block; &__items { - display: inline-flex; - gap: var(--_--gap); + display: flex; + gap: var(--g-pin-input-item-gap, var(--_--gap)); } &__item { flex: 0 0 auto; - width: var(--_--item-width); + width: var(--g-pin-input-item-width, var(--_--item-width)); } &__control { @@ -43,4 +43,13 @@ $block: '.#{variables.$ns}pin-input'; --_--gap: 12px; } } + + &_responsive { + display: block; + + #{$block}__item { + width: auto; + flex: 1 1 auto; + } + } } diff --git a/src/components/PinInput/PinInput.tsx b/src/components/PinInput/PinInput.tsx index a73ca16578..757299e861 100644 --- a/src/components/PinInput/PinInput.tsx +++ b/src/components/PinInput/PinInput.tsx @@ -35,6 +35,7 @@ export interface PinInputProps extends DOMProps, AriaLabelingProps, QAProps { autoFocus?: boolean; otp?: boolean; mask?: boolean; + responsive?: boolean; note?: TextInputProps['note']; validationState?: TextInputProps['validationState']; errorMessage?: TextInputProps['errorMessage']; @@ -69,6 +70,7 @@ export const PinInput = React.forwardRef((props, autoFocus, otp, mask, + responsive, note, validationState, errorMessage, @@ -244,7 +246,7 @@ export const PinInput = React.forwardRef((props, ); return ( -
+
{Array.from({length}).map((__, i) => (
diff --git a/src/components/PinInput/README.md b/src/components/PinInput/README.md index 5f4876929b..a52b534690 100644 --- a/src/components/PinInput/README.md +++ b/src/components/PinInput/README.md @@ -161,6 +161,13 @@ If you want the browser to suggest "one time codes" from the outer context (e.g. - `focus(): void` - Set focus to the current active input. +## CSS API + +| Name | Description | +| :------------------------- | :----------------------------------------------------- | +| `--g-pin-input-item-width` | Set width of each input, unless `responsive` is `true` | +| `--g-pin-input-item-gap` | Set gap between inputs | + ## Properties | Name | Description | Type | Default | @@ -184,6 +191,7 @@ If you want the browser to suggest "one time codes" from the outer context (e.g. | otp | When set to `true` adds `autocomplete="one-time-code"` to inputs | `boolean` | | | placeholder | Placeholder for inputs | `string` | | | qa | HTML `data-qa` attribute, for test purposes | `string` | | +| responsive | Parent's width distributed evenly between inputs | `boolean` | | | size | Size of input fields | `"s"` `"m"` `"l"` `"xl"` | `"m"` | | style | HTML `style` attribute | `React.CSSProperties` | | | type | What type of input value is allowed | `"numeric"` `"alphanumeric"` | `"numeric"` | diff --git a/src/components/PinInput/__stories__/PinInput.stories.tsx b/src/components/PinInput/__stories__/PinInput.stories.tsx index a15d54e8c0..7f76309747 100644 --- a/src/components/PinInput/__stories__/PinInput.stories.tsx +++ b/src/components/PinInput/__stories__/PinInput.stories.tsx @@ -114,3 +114,22 @@ export const WithNote: Story = { note: 'Additional info', }, }; + +export const Responsive: Story = { + render: (args) => ( +
+ +
+ ), + args: { + ...Default.args, + responsive: true, + }, +};