Skip to content

Commit

Permalink
Merge pull request #4240 from relative-ci/dropdown-disabled-state
Browse files Browse the repository at this point in the history
enhance(ui): Dropdown - add disabled state
  • Loading branch information
vio authored Feb 12, 2024
2 parents 04d3a74 + 511c88b commit 467a9df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
13 changes: 11 additions & 2 deletions packages/ui/src/ui/dropdown/dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ Item.defaultProps = {
};

export const Dropdown = (props) => {
const { className, buttonClassName, label, ariaLabel, glyph, children } = props;
const { className, buttonClassName, label, ariaLabel, glyph, disabled, children } = props;
const rootClassName = cx(css.root, className);
const menuState = useMenuState();

return (
<div className={rootClassName}>
<MenuButton state={menuState} className={cx(css.button, buttonClassName)} tabIndex={null}>
<MenuButton
state={menuState}
className={cx(css.button, buttonClassName)}
disabled={disabled}
tabIndex={null}
>
<FlexStack space="xxxsmall" alignItems="center" className={css.label}>
{glyph && <Icon className={css.labelIcon} glyph={glyph} />}
{label && <span className={css.labelText}>{label}</span>}
Expand All @@ -54,6 +59,7 @@ Dropdown.defaultProps = {
label: null,
ariaLabel: '',
glyph: null,
disabled: false,
};

Dropdown.propTypes = {
Expand All @@ -72,6 +78,9 @@ Dropdown.propTypes = {
/** Icon glyph */
glyph: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),

/** Dropdown button disabled attribute */
disabled: PropTypes.bool,

/** Content */
children: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func]).isRequired,
};
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/src/ui/dropdown/dropdown.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
color: var(--color-text);
}

.button[disabled] {
color: var(--color-text-ultra-light);
}

.dropdown {
position: absolute;
left: 0;
Expand Down
27 changes: 12 additions & 15 deletions packages/ui/src/ui/dropdown/dropdown.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@ export default {

export const Defualt = () => (
<Dropdown glyph="filter" label="Toggle">
<Dropdown.Item>
Option 1
</Dropdown.Item>
<Dropdown.Item>
Option 2
</Dropdown.Item>
<Dropdown.Item>Option 1</Dropdown.Item>
<Dropdown.Item>Option 2</Dropdown.Item>
</Dropdown>
);

export const Disabled = () => (
<Dropdown glyph="filter" label="Toggle" disabled>
<Dropdown.Item>Option 1</Dropdown.Item>
<Dropdown.Item>Option 2</Dropdown.Item>
</Dropdown>
);

export const WithRenderFn = () => (
<Dropdown glyph="filter" label="Toggle">
{({ MenuItem, menuItemClassName, menu }) => (
<>
<MenuItem className={menuItemClassName}>
Option 1
</MenuItem>
<MenuItem className={menuItemClassName}>
Option 2
</MenuItem>
<MenuItem className={menuItemClassName}>
Option 3
</MenuItem>
<MenuItem className={menuItemClassName}>Option 1</MenuItem>
<MenuItem className={menuItemClassName}>Option 2</MenuItem>
<MenuItem className={menuItemClassName}>Option 3</MenuItem>
<button type="button" onClick={menu.toggle}>
Toggle dropdown
</button>
Expand Down

0 comments on commit 467a9df

Please sign in to comment.