Skip to content

Commit

Permalink
Merge pull request #159 from the-deep/feature/add-disabled-in-dropdow…
Browse files Browse the repository at this point in the history
…n-item

Add disabled functionality in dropdown item
  • Loading branch information
samshara authored Nov 30, 2022
2 parents 4c07e29 + 7760b64 commit 252003d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/DropdownMenuItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function Separator({ className }: { className?: string }) {

interface BaseProps extends ElementFragmentProps {
className?: string;
disabled?: boolean;
}

export type Props<N extends string | number | undefined> = BaseProps & ({
Expand All @@ -61,12 +62,14 @@ function DropdownMenuItem<N extends string | number | undefined>(props: Props<N>
actionsContainerClassName,
spacing = 'comfortable',
href,
disabled = false,
} = props;

const className = _cs(
styles.dropdownMenuItem,
spacingToStyleMap[spacing],
classNameFromProps,
disabled && styles.disabled,
);

const content = (
Expand Down Expand Up @@ -116,6 +119,7 @@ function DropdownMenuItem<N extends string | number | undefined>(props: Props<N>
name={props.name}
// eslint-disable-next-line react/destructuring-assignment
onClick={props.onClick}
disabled={disabled}
>
{content}
</RawButton>
Expand Down
7 changes: 6 additions & 1 deletion src/components/DropdownMenuItem/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
&.loose-spacing {
--spacing: var(--dui-spacing-large);
}
}

&.disabled {
pointer-events: none;
opacity: var(--dui-opacity-disabled-element);
filter: saturate(var(--dui-saturation-disabled-element));
}
}
.separator {
margin: var(--dui-spacing-extra-small) 0;
border: var(--dui-width-separator-thin) solid var(--dui-color-separator);
Expand Down
29 changes: 29 additions & 0 deletions storybook/stories/DropdownMenu/DropdownMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,35 @@ export const Variants: Story = () => (
Goto Togglecorp
</DropdownMenuItem>
</DropdownMenu>
<DropdownMenu
variant="general"
label="Disabled items"
>
<DropdownMenuItem
name={undefined}
onClick={handleMenuItemClick}
disabled
>
Home
</DropdownMenuItem>
<DropdownMenuItem name={undefined} onClick={handleMenuItemClick}>
Profile
</DropdownMenuItem>
<DropdownMenuItem name={undefined} onClick={handleMenuItemClick}>
Projects
</DropdownMenuItem>
<Separator />
<DropdownMenuItem name={undefined} onClick={handleMenuItemClick}>
Logout
</DropdownMenuItem>
<DropdownMenuItem
href="https://togglecorp.com"
actions={<IoExitOutline />}
disabled
>
Goto Togglecorp
</DropdownMenuItem>
</DropdownMenu>
</div>
</section>
</div>
Expand Down

0 comments on commit 252003d

Please sign in to comment.