Skip to content

Commit

Permalink
Merge pull request #1 from octoml/add-dropdown
Browse files Browse the repository at this point in the history
feat: add dropdown
  • Loading branch information
chailandau authored Feb 20, 2024
2 parents 2dd55bd + 381280e commit 8b3f68c
Show file tree
Hide file tree
Showing 12 changed files with 1,376 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"next": "14.1.0",
"react": "^18",
"react-aria-components": "^1.1.1",
"react-dom": "^18"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions public/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/chevron.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/icons/favicon-16x16.png
Binary file not shown.
Binary file removed public/icons/favicon-32x32.png
Binary file not shown.
13 changes: 13 additions & 0 deletions src/components/Select/Select.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Canvas, Meta, ArgTypes } from '@storybook/blocks';

import * as SelectStories from './Select.stories';

<Meta of={SelectStories} />

# Select

<Canvas of={SelectStories.Default} />

### Props Table

<ArgTypes />
35 changes: 35 additions & 0 deletions src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Meta, StoryObj } from "@storybook/react";

import Select from ".";

const meta: Meta<typeof Select> = {
title: "Components/Select",
component: Select,
decorators: [
(Story) => (
<div className="container">
<Story />
</div>
),
],
};

export default meta;

type Story = StoryObj<typeof Select>;

export const Default: Story = {
args: {
listTitle: "Year",
listItems: [
{
value: "2024",
label: "2024",
},
{
value: "2023",
label: "2023",
},
],
},
};
40 changes: 40 additions & 0 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { FC } from "react";
import {
Button,
Label,
ListBox,
ListBoxItem,
Popover,
Select as ReactAriaSelect,
SelectValue,
} from "react-aria-components";

interface listItem {
value: string;
label: string;
}
interface SelectProps {
listTitle?: string;
listItems: listItem[];
}

const Select: FC<SelectProps> = ({ listTitle, listItems }) => (
<ReactAriaSelect className="select" defaultSelectedKey={"2024"}>
{listTitle && <Label>{listTitle}</Label>}
<Button>
<SelectValue />
<span aria-hidden="true" className="icon">
<img src="/icons/chevron.svg" />
</span>
</Button>
<Popover className="select-list">
<ListBox>
{listItems?.map((item) => (
<ListBoxItem id={item?.value}>{item?.label}</ListBoxItem>
))}
</ListBox>
</Popover>
</ReactAriaSelect>
);

export default Select;
3 changes: 3 additions & 0 deletions src/components/Select/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Select from "./Select";

export default Select;
40 changes: 40 additions & 0 deletions src/styles/components/select.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.select {
@apply flex items-center gap-3;
.react-aria-Label {
@apply font-normal text-gray-500 dark:text-gray-50;
}
& > button {
@apply flex w-[100px] items-center justify-between gap-3 rounded border border-gray-300 bg-gray-50 shadow-light dark:border-gray-600 dark:bg-opacity-5 dark:text-white dark:shadow-dark;
&[data-hovered],
&[data-focused] {
@apply border-gray-500 bg-gray-50 bg-none outline-none dark:border-gray-300 dark:bg-opacity-5;
}

.icon img {
@apply w-3;
}
}
}

.select-list {
@apply w-[var(--trigger-width)] rounded border border-gray-300 bg-gray-50 shadow-light dark:border-gray-600 dark:bg-opacity-5 dark:shadow-dark;
&[data-hovered],
&[data-focused] {
@apply outline-none;
}
.react-aria-ListBoxItem {
@apply relative px-4 py-9px;

&[data-hovered],
&[data-focused] {
@apply outline-none;
}
&[data-hovered],
&[data-focus-visible] {
@apply cursor-pointer bg-gray-200 dark:bg-opacity-10;
}
&[data-selected] {
@apply after:absolute after:right-3 after:top-[calc(50%-8px)] after:block after:h-4 after:w-4 after:bg-[url('/icons/check.svg')] after:bg-no-repeat;
}
}
}
7 changes: 4 additions & 3 deletions src/styles/main.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@import "./global.css";
@import "./components/chat.css";
@import "./components/footer.css";
@import "./components/header.css";
@import "./components/hero.css";
@import "./components/loading.css";
@import "./components/interactive.css";
@import "./components/chat.css";
@import "./components/footer.css";
@import "./components/loading.css";
@import "./components/select.css";
Loading

0 comments on commit 8b3f68c

Please sign in to comment.