Esta página aún no está disponible en tu idioma.
A dropdown component that takes care of all the annoying bits for you, with added support for programmatic triggers on top.
You can change the dropdowns position by supplying the align
prop.
---import { Dropdown, Button } from '@studiocms/ui/components';---
<Dropdown id='dropdown' options={[ { label: 'Option 1', value: 'opt-1'}, { label: 'Option 2', value: 'opt-2'}, ]} align='start'> <Button color='primary'> Start-aligned </Button></Dropdown>
<!-- Other buttons omitted for simplicity -->
import { class DropdownHelper
DropdownHelper } from '@studiocms/ui/components';
const const dropdown: DropdownHelper
dropdown = new new DropdownHelper(id: string, fullWidth?: boolean): DropdownHelper
A helper function to interact with dropdowns.
DropdownHelper('dropdown');
You can tell the dropdown wrapper to only show the dropdown when it’s children are right-clicked:
---import { Dropdown, Button } from '@studiocms/ui/components';---
<Dropdown id='dropdown' options={[ { label: 'Option 1', value: 'opt-1'}, { label: 'Option 2', value: 'opt-2'}, ]} triggerOn='right'> <Button color='primary'> Right Click </Button></Dropdown>
import { class DropdownHelper
DropdownHelper } from '@studiocms/ui/components';
const const dropdown: DropdownHelper
dropdown = new new DropdownHelper(id: string, fullWidth?: boolean): DropdownHelper
A helper function to interact with dropdowns.
DropdownHelper('dropdown');
You can disable a dropdown by passing the disabled
prop.
<Dropdown disabled {/* ... */}> <!-- ... --></Dropdown>
No, you read that right. You can customize the options too. You can individually disable them, turn them into links and also change their color to any of the default colors:
---import { Dropdown, Button } from '@studiocms/ui/components';---
<Dropdown id='dropdown' options={[ { label: 'Default', value: 'default', color: 'default' }, { label: 'Primary', value: 'primary', color: 'primary' }, { label: 'Success', value: 'success', color: 'success' }, { label: 'Warning', value: 'warning', color: 'warning' }, { label: 'Danger', value: 'danger', color: 'danger' }, { label: 'Disabled', value: 'disabled', disabled: true }, { label: 'As Link', value: 'custom-href', href: '/' }, ]}> <Button color='primary'> Customized Options </Button></Dropdown>
import { class DropdownHelper
DropdownHelper } from '@studiocms/ui/components';
const const dropdown: DropdownHelper
dropdown = new new DropdownHelper(id: string, fullWidth?: boolean): DropdownHelper
A helper function to interact with dropdowns.
DropdownHelper('dropdown');
You know how, this entire page, we’ve been assigning our DropdownHelper
to a variable? There’s a reason for that. The DropdownHelper allows
you to access some built-in functions for programmatically toggling, showing and hiding the dropdown. You can even register a callback for when one of the
dropdowns options has been clicked!
import { class DropdownHelper
DropdownHelper } from '@studiocms/ui/components';
const const dropdown: DropdownHelper
dropdown = new new DropdownHelper(id: string, fullWidth?: boolean): DropdownHelper
A helper function to interact with dropdowns.
DropdownHelper('dropdown');
const dropdown: DropdownHelper
dropdown.DropdownHelper.registerClickCallback: (func: (value: string) => void) => void
Registers a click callback for the dropdown options. Whenever one of the options
is clicked, the callback will be called with the value of the option.
registerClickCallback((value: string
value) => { // `value` will be the value you gave your option in the dropdown wrapper. any
console.any
log(value: string
value);});
// You can toggle the dropdown like this:const dropdown: DropdownHelper
dropdown.DropdownHelper.toggle: () => void
A function to toggle the dropdown.
toggle();
// Instead of toggling, you can simply show or hide the dropdown:const dropdown: DropdownHelper
dropdown.DropdownHelper.show: () => void
A function to show the dropdown.
show();const dropdown: DropdownHelper
dropdown.DropdownHelper.hide: () => void
A function to hide the dropdown.
hide();