import {
  Meta,
  Story,
  Canvas,
  Primary,
  Controls,
  Unstyled,
  Source,
} from '@storybook/addon-docs/blocks';
import { Select } from '../../src/lib/components/selectv2/Selectv2.component';

import * as SelectStories from './selectv2.stories';

<Meta name="Guideline" of={SelectStories} />

<style>{`
  .sbdocs-content h2 { margin-top: 5rem; }
  .sbdocs-content h3 { margin-top: 3rem; }
  .sbdocs-content .sb-story { margin-bottom: 0.5rem; }
  .sbdocs-content .sbdocs-preview { margin-bottom: 1.5rem; }
`}</style>

# Select

Select lets users choose one option from a list. Use it when the list is too long for radio buttons or when the options are dynamic.

For guidance on when to use Checkbox vs Toggle vs Radio vs Select, see [Guidelines/Selection Controls](?path=/docs/guidelines-selection-controls--stories).

## Label conventions

The label identifies the field, not the action. Place it above or to the left of the control.

- `Region` not `Select a region`
- `Storage class` not `Choose storage class`
- `Retention mode` not `Pick retention mode`

The placeholder is the text shown inside the control when nothing is selected. Leave it empty when the label above is sufficient. A contextual placeholder like `Select a region` is acceptable, especially when there is no visible label. Avoid generic placeholders that apply to any select in any interface.

- `Select a region` or empty, not `Select an option`
- `Choose a storage class` or empty, not `Choose a value`

## Usage

### Icons

You can use icons to differentiate options. When using icons, all options must have one. Mixing options with and without icons creates an inconsistent list.

<Canvas of={SelectStories.WithIcons} sourceState="none" />

### Inside a modal

When placing a Select inside a modal, add `menuPosition="fixed"` to prevent the dropdown from being clipped by the modal overflow.

<Canvas of={SelectStories.InsideModal} sourceState="none" />

## Variations

The select component come with multiple props allowing customization and adaptation to various scenarios.

### Size variations

By default the Select component width is 20.5rem .
You can reduce its size by defining the 'size' props to two third, half or one third of the default size :

<Story of={SelectStories.DifferentSizes} />

### Options number

Depending on the number of options provided to the select, different features will be automatically enabled.

#### No option

When no option are provided, a clear information will be given to the user

<Story of={SelectStories.WithoutOptions} />

#### Scrollbar

When the number of options exceeds four, a scrollbar appears, allowing users to scroll through the available options.

<Story of={SelectStories.WithScrollbar} />

#### Search bar

If the number of options is greater than eight,
a search bar is automatically added, enabling users to quickly find and select options.

<Story of={SelectStories.WithSearchBar} />

### Disable state

#### Select

The Select component can be easily disabled, preventing user interaction.
This is useful in scenarios where user input is not allowed or required

<Story of={SelectStories.DisabledSelect} />

#### Options

Disable an option when it exists in the system but is not available in the current context, and the user has a reason to know it exists. For example, a retention mode that requires a license: disabling it with an explanation lets the user understand what is possible, not just what is available right now.

Hide an option when it is not relevant in the current context and showing it would create confusion.

<Canvas of={SelectStories.WithDisabledOptionsWithoutMessage} sourceState="hidden" />

Adding a `disabledReason` is strongly recommended. Without it, the user has no way to understand what is blocking them or what to do next.

<Canvas of={SelectStories.WithDisabledOptionsWithMessage} sourceState="hidden" />

### Dropdown Placement

In cases where there is limited space at the bottom of the viewport,
the dropdown menu opens toward the top to ensure visibility and usability.

<Canvas of={SelectStories.NotEnoughPlaceAtTheBottom} sourceState="hidden" />

<div style={{ height: '5rem' }} />
