Skip to content

Commit

Permalink
feat(select): select style
Browse files Browse the repository at this point in the history
  • Loading branch information
Gypsophyllite committed May 19, 2023
1 parent 7ce2f19 commit 1355d3a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 34 deletions.
12 changes: 5 additions & 7 deletions packages/design/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import Select from '.';

const componentMeta: ComponentMeta<typeof Select> = {
const componentMeta: Meta<typeof Select> = {
title: 'Modern/Select',
component: Select,
};

export default componentMeta;

const Template: ComponentStory<typeof Select> = () => {
return (
export const Template: StoryObj<typeof Select> = {
render: () => (
<Select
style={{
width: 400,
Expand All @@ -23,7 +23,5 @@ const Template: ComponentStory<typeof Select> = () => {
]}
defaultValue='age'
/>
);
),
};

export const Default = Template.bind({});
20 changes: 19 additions & 1 deletion packages/design/components/Select/__test__/Select.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render } from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';

import Select from '..';
Expand All @@ -16,4 +16,22 @@ describe('Select Component', () => {
);
expect(container).toMatchSnapshot();
});

it('Open dropdown & Select option', () => {
const onChange = vi.fn();
const element = render(
<Select
defaultValue='name'
options={[
{ label: 'name', value: 'name' },
{ label: 'age', value: 'age' },
]}
onChange={onChange}
/>,
);

fireEvent.click(element.getByText('name'));
fireEvent.click(element.getByText('age'));
expect(onChange).toBeCalledTimes(1);
});
});

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

30 changes: 18 additions & 12 deletions packages/design/components/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ const Select = ({ options, style, defaultValue, className, onChange }: SelectPro
<span>{optionsMap[active]?.label}</span>
<ArrowDown className='bgm-select-arrow' />
</div>
<select
defaultValue={defaultValue}
onChange={(e) => {
handleOptionClick(e.target.value);
}}
>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
{open ? (
<ul className={cn('bgm-select__dropdown')} defaultValue={defaultValue}>
{options.map((option) => (
<li
className={cn('bgm-select__dropdown-item')}
key={option.value}
value={option.value}
onClick={() => {
handleOptionClick(option.value);
}}
>
{option.label}
</li>
))}
</ul>
) : (
<></>
)}
</div>
);
};
Expand Down
12 changes: 11 additions & 1 deletion packages/design/components/Select/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
top: 100%;
border: 2px solid @gray-10;
box-sizing: border-box;
padding: 8px 12px;
padding: 10px 0;
width: 100%;
left: 0;
border-radius: 19px;
Expand All @@ -27,6 +27,16 @@
> div {
padding: 9px 0;
}

&-item {
height: 1em;
padding: 10px;
// padding: 0.5em 0;

&:hover {
background-color: @gray-10;
}
}
}

select {
Expand Down

0 comments on commit 1355d3a

Please sign in to comment.