Add select component
This commit is contained in:
parent
1f91ebe86f
commit
6a65299918
10
libs/ui-toolkit/src/components/select/select.spec.tsx
Normal file
10
libs/ui-toolkit/src/components/select/select.spec.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import Select from './select';
|
||||
|
||||
describe('Select', () => {
|
||||
it('should render successfully', () => {
|
||||
const { baseElement } = render(<Select />);
|
||||
expect(baseElement).toBeTruthy();
|
||||
});
|
||||
});
|
26
libs/ui-toolkit/src/components/select/select.stories.tsx
Normal file
26
libs/ui-toolkit/src/components/select/select.stories.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { Story, Meta } from '@storybook/react';
|
||||
import { Select } from './select';
|
||||
|
||||
export default {
|
||||
component: Select,
|
||||
title: 'Select',
|
||||
} as Meta;
|
||||
|
||||
const Template: Story = (args) => (
|
||||
<Select {...args}>
|
||||
<option value="Only option">Only option</option>
|
||||
</Select>
|
||||
);
|
||||
|
||||
export const Default = Template.bind({});
|
||||
Default.args = {};
|
||||
|
||||
export const WithError = Template.bind({});
|
||||
WithError.args = {
|
||||
hasError: true,
|
||||
};
|
||||
|
||||
export const Disabled = Template.bind({});
|
||||
Disabled.args = {
|
||||
disabled: true,
|
||||
};
|
36
libs/ui-toolkit/src/components/select/select.tsx
Normal file
36
libs/ui-toolkit/src/components/select/select.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
import classNames from 'classnames';
|
||||
import { inputClassNames, inputStyle } from '../input/input';
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
export interface TextAreaProps {
|
||||
onChange?: React.FormEventHandler<HTMLSelectElement>;
|
||||
hasError?: boolean;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
value?: string | number;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export function Select({
|
||||
hasError,
|
||||
onChange,
|
||||
disabled,
|
||||
className,
|
||||
children,
|
||||
}: TextAreaProps) {
|
||||
return (
|
||||
<select
|
||||
onChange={onChange}
|
||||
className={classNames(
|
||||
inputClassNames({ hasError, disabled, className }),
|
||||
'h-28'
|
||||
)}
|
||||
disabled={disabled}
|
||||
style={inputStyle({ disabled })}
|
||||
>
|
||||
{children}
|
||||
</select>
|
||||
);
|
||||
}
|
||||
|
||||
export default Select;
|
@ -1,4 +1,4 @@
|
||||
import classNames from 'classnames';
|
||||
import { inputClassNames, inputStyle } from '../input/input';
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
export interface TextAreaProps {
|
||||
@ -10,47 +10,6 @@ export interface TextAreaProps {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const inputClassNames = ({
|
||||
hasError,
|
||||
disabled,
|
||||
className,
|
||||
}: {
|
||||
hasError?: boolean;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}) =>
|
||||
classNames(
|
||||
[
|
||||
'inline-flex',
|
||||
'items-center',
|
||||
'box-border',
|
||||
'pl-8',
|
||||
'pr-8',
|
||||
'border',
|
||||
'border-light-gray-50',
|
||||
'bg-neutral-753',
|
||||
'text-light-gray-50',
|
||||
'text-ui',
|
||||
'focus-visible:shadow-focus',
|
||||
'focus-visible:outline-0',
|
||||
],
|
||||
{
|
||||
'border-vega-pink': hasError,
|
||||
'text-disabled': disabled,
|
||||
'bg-transparent': disabled,
|
||||
},
|
||||
className
|
||||
);
|
||||
|
||||
export const inputStyle = ({ disabled }: { disabled?: boolean }) => {
|
||||
const style: React.CSSProperties = {};
|
||||
if (disabled) {
|
||||
style.backgroundImage =
|
||||
'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAYAAADgzO9IAAAAAXNSR0IArs4c6QAAACNJREFUGFdjtLS0/M8ABcePH2eEsRlJl4BpBdHIuuFmEi0BABqjEQVjx/LTAAAAAElFTkSuQmCC)';
|
||||
}
|
||||
return style;
|
||||
};
|
||||
|
||||
export function TextArea({
|
||||
hasError,
|
||||
onChange,
|
||||
|
Loading…
Reference in New Issue
Block a user