Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PinInput): responsive prop and CSS API #1679

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/components/PinInput/PinInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -43,4 +43,13 @@ $block: '.#{variables.$ns}pin-input';
--_--gap: 12px;
}
}

&_responsive {
display: block;

#{$block}__item {
width: auto;
flex: 1 1 auto;
}
}
}
4 changes: 3 additions & 1 deletion src/components/PinInput/PinInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -69,6 +70,7 @@ export const PinInput = React.forwardRef<HTMLDivElement, PinInputProps>((props,
autoFocus,
otp,
mask,
responsive,
note,
validationState,
errorMessage,
Expand Down Expand Up @@ -244,7 +246,7 @@ export const PinInput = React.forwardRef<HTMLDivElement, PinInputProps>((props,
);

return (
<div ref={ref} className={b({size}, className)} style={style} data-qa={qa}>
<div ref={ref} className={b({size, responsive}, className)} style={style} data-qa={qa}>
<div className={b('items')}>
{Array.from({length}).map((__, i) => (
<div key={i} className={b('item')}>
Expand Down
8 changes: 8 additions & 0 deletions src/components/PinInput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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"` |
Expand Down
19 changes: 19 additions & 0 deletions src/components/PinInput/__stories__/PinInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,22 @@ export const WithNote: Story = {
note: 'Additional info',
},
};

export const Responsive: Story = {
render: (args) => (
<div
style={{
resize: 'horizontal',
width: 200,
overflow: 'scroll',
paddingBottom: 16,
}}
>
<PinInput {...args} />
</div>
),
args: {
...Default.args,
responsive: true,
},
};
Loading