Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Select dropdown #7

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ function App() {
createRoot.render(<App />, document.querySelector('#app'));
```

## Component List
| Component | Source Code |
| -------- | ------- |
| Highlighter | [lib/components/highlighter.tsx](lib/components/highlighter.tsx) |
| Select | [lib/components/select.tsx](lib/components/select.tsx) |


## How to use

1. Clone this repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ export const Highlight = ({ id, children: child }: HighlightProps) => {
</div>
</div>
);
};
};
47 changes: 47 additions & 0 deletions lib/components/select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Option, Select as MTSelect } from '@material-tailwind/react';

export interface OptionType {
label: string;
value: string;
}

interface SelectProps {
options: OptionType[];
id: string;
value: string;
onChange: React.Dispatch<React.SetStateAction<string>>;
}

export const Select = ({ options, id, value, onChange }: SelectProps) => {
const handleChange = (val: string | undefined) => {
if (val) {
onChange(val);
}
};

return (
<MTSelect
id={id}
data-testid={`select-dropdown-${id}`}
value={value}
onChange={handleChange}
className="!border border-t-1 !border-gray-300 bg-white text-gray-900 placeholder:text-gray-500 placeholder:opacity-100 focus:!border-gray-900 focus:ring-gray-900/10"
labelProps={{
className: 'hidden',
}}
>
{options.map((option, index) => {
return (
<Option
key={`${id}-dropdown-${index}`}
value={option.value}
>
{option.label}
</Option>
);
})}
</MTSelect>
);
};

export default Select;
3 changes: 2 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import './global.css';

export { default as tailwindConfig } from './tailwind.config';
export { default as TRIApp, type TRIAppConfig, useTRIAppContext } from './tri-app';
export { Highlight, Highlighter } from './components/Highlighter';
export { Highlight, Highlighter } from './components/highlighter';
export { useUserAuth } from './amplify/use-user-auth';
export { Select } from './components/select';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toyota-research-institute/rse-react-library",
"version": "0.0.15",
"version": "0.0.16",
"description": "RSE React component libraries with Vite, Tailwind, Material Tailwind and Storybook.",
"author": "TRI",
"license": "MIT",
Expand Down