Skip to content

Commit

Permalink
feat(ui) added select, spinner components
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilmhdh committed Jan 23, 2023
1 parent e7ac74c commit ad504fa
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 51 deletions.
4 changes: 4 additions & 0 deletions frontend/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { themes } from '@storybook/theming';
import '../src/styles/globals.css';

export const parameters = {
Expand All @@ -7,5 +8,8 @@ export const parameters = {
color: /(background|color)$/i,
date: /Date$/
}
},
darkMode: {
dark: { ...themes.dark, appContentBg: '#0e1014', appBg: '#0e1014' }
}
};
116 changes: 66 additions & 50 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"prettier": "^2.8.3",
"storybook": "^7.0.0-beta.30",
"storybook-dark-mode": "^2.0.5",
"tailwindcss": "^3.1.4",
"tailwindcss": "3.2",
"typescript": "^4.9.3"
}
}
113 changes: 113 additions & 0 deletions frontend/src/components/v2/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { useEffect, useState } from 'react';
import { SelectProps } from '@radix-ui/react-select';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Meta, StoryObj } from '@storybook/react';

import { Select, SelectItem } from './Select';

const meta: Meta<typeof Select> = {
title: 'Components/Select',
component: Select,
tags: ['v2'],
argTypes: {
placeholder: {
defaultValue: 'Type something...'
}
}
};

export default meta;
type Story = StoryObj<typeof Select>;

export const Basic: Story = {
render: (args) => (
<div className="">
<Select placeholder="Type anything..." className="w-72" {...args}>
<SelectItem value="1">John</SelectItem>
<SelectItem value="2">Peter</SelectItem>
<SelectItem value="3">Suzy</SelectItem>
</Select>
</div>
)
};

const Controlled = (args: SelectProps) => {
const [isOpen, setIsOpen] = useState(false);
const [selected, setSelected] = useState('');

return (
<div className="">
<Select
defaultValue="1"
className="w-72"
open={isOpen}
onValueChange={(val) => setSelected(val)}
value={selected}
onOpenChange={(open) => setIsOpen(open)}
{...args}
>
<SelectItem value="1">John</SelectItem>
<SelectItem value="2">Peter</SelectItem>
<SelectItem value="3">Suzy</SelectItem>
</Select>
</div>
);
};

export const Control: Story = {
render: (args) => <Controlled {...args} />
};

export const Disabled: Story = {
render: (args) => (
<div className="">
<Select defaultValue="1" className="w-72" {...args}>
<SelectItem value="1">John</SelectItem>
<SelectItem value="2" isDisabled>
Peter
</SelectItem>
<SelectItem value="3">Suzy</SelectItem>
</Select>
</div>
)
};

export const Loading: Story = {
render: (args) => (
<div className="">
<Select defaultValue="1" className="w-72" isLoading {...args}>
<SelectItem value="1">John</SelectItem>
<SelectItem value="2">Peter</SelectItem>
<SelectItem value="3">Suzy</SelectItem>
</Select>
</div>
)
};

const AsyncSelectOptions = () => {
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
// eslint-disable-next-line no-new
new Promise<void>((resolve): void => {
setTimeout(() => {
setIsLoading(false);
resolve();
}, 1000);
});
}, []);

return (
<div className="">
<Select placeholder="Hello" className="w-72" isLoading={isLoading}>
<SelectItem value="1">John</SelectItem>
<SelectItem value="2">Peter</SelectItem>
<SelectItem value="3">Suzy</SelectItem>
</Select>
</div>
);
};

export const Async: Story = {
render: (args) => <AsyncSelectOptions {...args} />
};
Loading

0 comments on commit ad504fa

Please sign in to comment.