Skip to content

Commit

Permalink
Updated dropdown with custom items
Browse files Browse the repository at this point in the history
  • Loading branch information
belousovjr committed Nov 14, 2023
1 parent a7522f6 commit c019933
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/components/Dropdown/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DropdownComponent from "./index";
import { useState } from "react";
import { Box, Grid } from "../Box";
import { Box, Flex, Grid } from "../Box";
import Text from "../Text";

export default {
Expand All @@ -13,6 +13,14 @@ export const Dropdown = () => {
const [value, setValue] = useState(1);
const [value2, setValue2] = useState(1);
const [value3, setValue3] = useState(1);

const CustomItem = (color: string, value: string) => (
<Flex alignItems={"center"}>
<Box width={"10px"} height={"10px"} borderRadius={"5px"} background={color} mr={"4px"}></Box>
<span>{value}</span>
</Flex>
);

return (
<Grid gridTemplateColumns={"repeat(3, 1fr)"} mt={"10px"}>
<Box>
Expand All @@ -32,14 +40,18 @@ export const Dropdown = () => {
</Box>
<Box>
<Text variant={"h5"} mb="20px">
With long title
With custom items
</Text>
<DropdownComponent
items={[
{ value: 1, title: "Short" },
{ value: 2, title: "Short" },
{ value: 3, title: "Looooooooooooooooong" },
{ value: 4, title: "Short" },
{
value: 1,
title: CustomItem("#EF4625", "1%"),
},
{ value: 2, title: CustomItem("#63F6FF", "0.3%") },
{ value: 3, title: CustomItem("#F7EF2B", "0.15%") },
{ value: 4, title: CustomItem("#AAC772", "0.05%") },
{ value: 5, title: CustomItem("#5F72D6", "0%") },
]}
value={value2}
onChange={setValue2}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Dropdown/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ReactNode } from "react";

export type DropdownItemValue = string | number;
export interface IDropdownProps {
items: { title?: string; value?: DropdownItemValue }[];
items: { title?: ReactNode; value?: DropdownItemValue }[];
value?: DropdownItemValue;
onChange?: (value?: DropdownItemValue) => void;
}
}

0 comments on commit c019933

Please sign in to comment.