import { Select } from '@frontile/forms';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { array } from '@ember/helper';
import { Select } from '@frontile/forms';
import { Divider } from '@frontile/utilities';
const animals = [
'cheetah',
'crocodile',
'elephant',
'giraffe',
'kangaroo',
'koala',
'lemming',
'lemur',
'lion',
'lobster',
'panda',
'penguin',
'tiger',
'zebra'
];
const animalsAsOject = [
{ key: 'cheetah', label: 'Cheetah' },
{ key: 'crocodile', label: 'Crocodile' },
{ key: 'elephant', label: 'Elephant' },
{ key: 'giraffe', label: 'Giraffe' },
{ key: 'kangaroo', label: 'Kangaroo' },
{ key: 'koala', label: 'Koala' },
{ key: 'lemming', label: 'Lemming' },
{ key: 'lemur', label: 'Lemur' },
{ key: 'lion', label: 'Lion' },
{ key: 'lobster', label: 'Lobster' },
{ key: 'panda', label: 'Panda' },
{ key: 'penguin', label: 'Penguin' },
{ key: 'tiger', label: 'Tiger' },
{ key: 'zebra', label: 'Zebra' }
];
export default class Example extends Component {
@tracked selectedKeys: string[] = [];
@tracked selectedKeys2: string[] = ['elephant'];
@tracked selectedKeys3: string[] = [];
@action
onChange(value: boolean): void {
this.isSelected = value;
}
@action
onAction(key: string) {
// eslint-disable-next-line
console.log('Click on key', key);
}
@action
onSelectionChange(keys: string[]) {
this.selectedKeys = keys;
}
@action
onSelectionChange2(keys: string[]) {
this.selectedKeys2 = keys;
}
@action
onSelectionChange3(keys: string[]) {
this.selectedKeys3 = keys;
}
<template>
<Select
@selectionMode="multiple"
@items={{animals}}
@onAction={{this.onAction}}
@selectedKeys={{this.selectedKeys}}
@onSelectionChange={{this.onSelectionChange}}
>
<:item as |o|>
<o.Item @key={{o.item}} @intent="default" @appearance="faded">
{{o.item}}
</o.Item>
</:item>
</Select>
Values:
{{this.selectedKeys}}
<Divider @class="my-8" />
<Select
@placeholder="select an option my friend"
@allowEmpty={{true}}
@selectionMode="single"
@items={{animalsAsOject}}
@intent="primary"
@selectedKeys={{this.selectedKeys2}}
@onAction={{this.onAction}}
@onSelectionChange={{this.onSelectionChange2}}
/>
Values:
{{this.selectedKeys2}}
<Divider @class="my-8" />
<Select
@disableTransitions={{true}}
@onAction={{this.onAction}}
@disabledKeys={{(array "notifications")}}
@selectedKeys={{this.selectedKeys3}}
@onSelectionChange={{this.onSelectionChange3}}
as |l|
>
<l.Item @key="profile" @description="View my profile">
My Profile
</l.Item>
<l.Item @key="settings" @shortcut="⌘⇧S">Settings</l.Item>
<l.Item @key="notifications" @shortcut="⌘⇧N" @withDivider={{true}}>
Notifications
</l.Item>
<l.Item @key="reset" @intent="danger" @class="text-danger">
<:start>
<div>Start</div>
</:start>
<:default>
Reset Settings
</:default>
</l.Item>
<l.Item
@key="delete"
@shortcut="⌘⇧D"
@intent="danger"
@appearance="faded"
@class="text-danger"
>
Delete Account
</l.Item>
</Select>
Values:
{{this.selectedKeys3}}
</template>
}
Element: HTMLDivElement
Name | Type | Default | Description |
---|---|---|---|
allowEmpty
|
boolean
|
- | |
appearance
|
enum
|
'default'
|
The appearance of each item |
backdrop
|
enum
|
- | |
backdropTransition
|
Object
|
- | |
blockScroll
|
boolean
|
true
|
|
classes
|
SlotsToClasses<'base' | 'input' | 'innerContainer' | 'startContent' | 'endContent' | 'icon' | 'placeholder' | 'listbox' | 'clearButton'>
|
- | |
closeOnEscapeKey
|
boolean
|
true
|
Whether to close when the escape key is pressed |
closeOnItemSelect
|
boolean
|
true
|
Whether the select should close upon selecting an item. |
closeOnOutsideClick
|
boolean
|
true
|
Whether to close when the area outside (the backdrop) is clicked |
description
|
string
|
- | |
didClose
|
function
|
- | |
disabledKeys
|
Array
|
- | |
disableFocusTrap
|
boolean
|
false
|
|
disableTransitions
|
boolean
|
false
|
Disable css transitions |
endContentPointerEvents
|
enum
|
'none'
|
Controls pointer-events property of endContent. Defauled to `none` to pass the click event to the input. If your content needs to capture events, consider adding `pointer-events-auto` class to that element only. |
errors
|
enum
|
- | |
flipOptions
|
{ mainAxis?: boolean; crossAxis?: boolean; fallbackPlacements?: Placement[]; fallbackStrategy?: 'bestFit' | 'initialPlacement'; fallbackAxisSideDirection?: 'none' | 'start' | 'end'; ... 5 more ...; boundary?: Boundary; }
|
- | |
focusTrapOptions
|
unknown
|
{ clickOutsideDeactivates: true, allowOutsideClick: true }
|
Focus trap options |
id
|
string
|
- | |
inputSize
|
enum
|
- | |
intent
|
enum
|
- | The intent of each item |
isClearable
|
boolean
|
false
|
Whether to include a clear button. It ignores the option allowEmpty. |
isDisabled
|
boolean
|
- | |
isInvalid
|
boolean
|
- | |
isRequired
|
boolean
|
- | |
items
|
Array
|
- | |
label
|
string
|
- | |
middleware
|
Array
|
- | |
name
|
string
|
- | |
offsetOptions
|
enum
|
5
|
|
onAction
|
function
|
- | |
onSelectionChange
|
function
|
- | |
placeholder
|
string
|
- | |
placement
|
enum
|
'bottom-start'
|
Placement of the menu when open |
popoverSize
|
enum
|
- | |
renderInPlace
|
boolean
|
false
|
Whether to render in place or in the specified/default destination |
selectedKeys
|
Array
|
- | |
selectionMode
|
enum
|
- | |
shiftOptions
|
{ mainAxis?: boolean; crossAxis?: boolean; rootBoundary?: RootBoundary; elementContext?: ElementContext; altBoundary?: boolean; padding?: Padding; limiter?: { ...; }; boundary?: Boundary; }
|
- | |
startContentPointerEvents
|
enum
|
'auto'
|
Controls pointer-events property of startContent. If you want to pass the click event to the input, set it to `none`. |
strategy
|
enum
|
'absolute'
|
|
target
|
enum
|
- | The target where to render the portal. There are 3 options: 1) `Element` object, 2) element id, 3) portal target name. For element id, string must be prefixed with `#`. If no value is passee in, we will render to the closest unnamed portal target, parent portal or `document.body`. |
transition
|
Object
|
{name: 'overlay-transition--scale'}
|
The transition to be used in the Modal. |
transitionDuration
|
number
|
200
|
Duration of the animation |
Name | Type | Default | Description |
---|---|---|---|
item
*
|
Array
|
- | |
default
*
|
Array
|
- | |
startContent
*
|
Array
|
- | |
endContent
*
|
Array
|
- |
Name | Type | Default | Description |
---|
Element: <span class="hljs-built_in">Array</span>
Name | Type | Default | Description |
---|---|---|---|
allowEmpty
|
boolean
|
- | |
classes
|
SlotsToClasses<'base' | 'input' | 'innerContainer' | 'startContent' | 'endContent' | 'icon'>
|
- | |
description
|
string
|
- | |
disabledKeys
|
Array
|
- | |
endContentPointerEvents
|
enum
|
'none'
|
Controls pointer-events property of endContent. Defauled to `none` to pass the click event to the input. If your content needs to capture events, consider adding `pointer-events-auto` class to that element only. |
errors
|
enum
|
- | |
id
|
string
|
- | |
isInvalid
|
boolean
|
- | |
isRequired
|
boolean
|
- | |
items
|
Array
|
- | |
label
|
string
|
- | |
name
|
string
|
- | |
onAction
|
function
|
- | |
onItemsChange
|
function
|
- | |
onSelectionChange
|
function
|
- | |
placeholder
|
string
|
- | Placeholder text used when `allowEmpty` is set to `true`. |
selectedKeys
|
Array
|
- | |
selectionMode
|
enum
|
- | |
size
|
enum
|
- | |
startContentPointerEvents
|
enum
|
'auto'
|
Controls pointer-events property of startContent. If you want to pass the click event to the input, set it to `none`. |
Name | Type | Default | Description |
---|---|---|---|
item
*
|
Array
|
- | |
default
*
|
Array
|
- | |
startContent
*
|
Array
|
- | |
endContent
*
|
Array
|
- |
Element: HTMLOptionElement
Name | Type | Default | Description |
---|---|---|---|
key
*
|
string
|
- | |
manager
*
|
ListManager
|
- | |
textValue
|
string
|
- |
Name | Type | Default | Description |
---|---|---|---|
default
*
|
Array
|
- | |
selectedIcon
*
|
Array
|
- | |
start
*
|
Array
|
- | |
end
*
|
Array
|
- |