Skip to content

Commit

Permalink
Add Custom Format Option Label story (#5476)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebennett88 committed Nov 11, 2022
1 parent eda8885 commit 0aad8d5
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions storybook/stories/CustomFormatOptionLabel.stories.tsx
@@ -0,0 +1,44 @@
import type { ComponentMeta } from '@storybook/react';
import * as React from 'react';
import Select from 'react-select';
import { Field } from '../components';

import { colourOptions } from '../data';

export default {
title: 'Select/CustomFormatOptionLabel',
component: Select,
argTypes: {},
} as ComponentMeta<typeof Select>;

export function CustomFormatOptionLabel() {
return (
<Field
label="Custom Format Option Label"
htmlFor="custom-format-option-label-id"
>
<Select
inputId="custom-format-option-label-id"
defaultValue={colourOptions[2]}
options={colourOptions}
formatOptionLabel={formatOptionLabel}
/>
</Field>
);
}

function formatOptionLabel(option: typeof colourOptions[number]) {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: '0.25rem' }}>
<div
style={{
backgroundColor: option.color,
borderRadius: 9999,
height: 8,
width: 8,
}}
/>
<div>{option.label}</div>
</div>
);
}

0 comments on commit 0aad8d5

Please sign in to comment.