Components
ActionDropdown

ActionDropdown

The ActionDropdown component provides a dropdown menu that appears when a button is clicked. It is often used to group related actions or options together in a dropdown menu.

Props

The ActionDropdown component accepts the following props:

NameTypeDefaultDescription
buttonstring, ReactElement, or ReactElement[]The content of the button that triggers the dropdown.
childrenstring, ReactElement, or ReactElement[]The content of the dropdown menu.
showbooleanIf true, the dropdown menu is shown; otherwise, it is hidden.
onClose() => voidA callback function called when the dropdown menu is closed.

ActionDropdownItem

The ActionDropdownItem component represents an item within an ActionDropdown. It is used to define individual actions or options within the dropdown menu.

Props

The ActionDropdownItem component accepts the following props:

NameTypeDefaultDescription
childrenstring, ReactElement, or ReactElement[]The content of the item.
iconIconPropAn optional icon to display alongside the item.
suffixIconIconPropAn optional icon to display after the item.
prefixstring, ReactElement, or ReactElement[]An optional element to display before the item.
suffixstring, ReactElement, or ReactElement[]An optional element to display after the item.
onClick() => voidA callback function called when the item is clicked.
primarybooleanIf true, the item is styled as a primary action.
dangerbooleanIf true, the item is styled as a danger action.
disabledbooleanIf true, the item is disabled and cannot be interacted with.
closeAfterClickbooleantrueIf true, the dropdown menu is closed after the item is clicked.

Try It

import { ActionDropdown, ActionDropdownItem, Button, Divider } from '@kloktun/uikit';
import { useState } from 'react'
import DuckIcon from './duck-icon.tsx'
import SearchIcon from './search-icon.tsx'

export default function ActionDropdownExample() {
  const [showDropdown, setShowDropdown] = useState(false);

  const handleToggleDropdown = () => {
    setShowDropdown(!showDropdown);
  };

  return (
    <div className="flex flex-row">
        <ActionDropdown show={showDropdown} onClose={() => setShowDropdown(false)} button={<Button onClick={handleToggleDropdown}>Toggle Dropdown</Button>}>
            <ActionDropdownItem onClick={() => alert('Edit clicked')}>Edit</ActionDropdownItem>

            <ActionDropdownItem primary onClick={() => alert('Save clicked')}>Save</ActionDropdownItem>
            <ActionDropdownItem danger onClick={() => alert('Delete clicked')}>Delete</ActionDropdownItem>
            <ActionDropdownItem warning onClick={() => alert('Warning clicked')}>Warning</ActionDropdownItem>
            <ActionDropdownItem success onClick={() => alert('Success clicked')} >Success</ActionDropdownItem>

            <Divider />

            <ActionDropdownItem icon={<DuckIcon />} >With icon</ActionDropdownItem>
            <ActionDropdownItem suffixIcon={<SearchIcon />}>With suffix icon</ActionDropdownItem>

            <Divider />

            <ActionDropdownItem  onClick={() => alert('Clicked, but not close dropdown')} closeAfterClick={false} >Click, but not close</ActionDropdownItem>
            <ActionDropdownItem  disabled >Disabled</ActionDropdownItem>

        </ActionDropdown>
    </div>
  );
}