-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from NJUPT-SAST/dev-uni
feat: select component
- Loading branch information
Showing
8 changed files
with
321 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
"input", | ||
"badge", | ||
"calendar", | ||
"card" | ||
"card", | ||
"select" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Wraper from '../../tools/wraper/index' | ||
import { Select } from '@sast/ui-universal' | ||
|
||
# Select Component | ||
|
||
The Select component provides a dropdown menu with selectable options. | ||
|
||
<Wraper> | ||
<div style={{margin: 10}}> | ||
<Select | ||
title="Select an option" | ||
optionsList={[ | ||
{ value: "1", label: "Next.js" }, | ||
{ value: "2", label: "Lit Element" }, | ||
{ value: "3", label: "Nuxt.js" } | ||
]} | ||
onchange={(value) => console.log("Selected option:", value)} | ||
selectKey={0} | ||
width={400} | ||
placeHolder="Please select" | ||
/> | ||
</div> | ||
</Wraper> | ||
|
||
## Props | ||
|
||
| Property | Description | Type | Default | | ||
|--------------------|--------------------------------------------------|-----------------------------------------------|----------| | ||
| `onchange` | Callback function triggered when an option is selected. | `(value: OptionProps) => void` | | | ||
| `optionsList` | List of options for the select menu. | `Array<OptionProps>` | | | ||
| `title` | Title of the select. | `string` | | | ||
| `disabled` | If `true`, the select will be disabled. | `boolean` | `false` | | ||
| `selectKey` | The currently selected option key. | `number` | `0` | | ||
| `isBorder` | If `true`, the select will have a border. | `boolean` | `true` | | ||
| `width` | The width of the select. | `number` | `200` | | ||
| `placeHolder` | Placeholder text displayed when no option is selected. | `string` | `"Please select"` | | ||
|
||
## Events | ||
|
||
- `onchange`: Fired when an option is selected. Provides the selected option as an argument to the callback function. | ||
|
||
## Example | ||
|
||
```jsx | ||
import { Select } from '@sast/ui-universal' | ||
|
||
|
||
export default function Example() { | ||
const handleSelect = (value) => { | ||
console.log("Selected option:", value); | ||
}; | ||
|
||
return ( | ||
<div style={{ margin: 10 }}> | ||
<Select | ||
title="Select an option" | ||
optionsList={[ | ||
{ value: "1", label: "Next.js" }, | ||
{ value: "2", label: "Lit Element" }, | ||
{ value: "3", label: "Nuxt.js" } | ||
]} | ||
onchange={(value) => console.log("Selected option:", value)} | ||
selectKey={0} | ||
width={400} | ||
placeHolder="Please select" | ||
/> | ||
</div> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@use '../../variables' as *; | ||
@use '../../_variables/color.scss' as *; | ||
@use '../../_variables/duration.scss' as *; | ||
@use '../../_variables/animation.scss' as *; | ||
@mixin select-option { | ||
border-radius: 5px; | ||
cursor: pointer; | ||
color: $primary-color; | ||
} | ||
$animation-duration: $duration-300; | ||
.input { | ||
input::placeholder { | ||
transition: all $animation-duration $cubic-bezier; | ||
color: $black-color; | ||
} | ||
&.hide-placeholder { | ||
input::placeholder { | ||
color: $gray-color; | ||
} | ||
} | ||
} | ||
.options { | ||
position: absolute; | ||
width: 280px; | ||
box-sizing: border-box; | ||
z-index: 1; | ||
margin-top: 3px; | ||
flex-direction: column; | ||
gap: 4px; | ||
padding: 7px 8px; | ||
font-size: 14px; | ||
max-height: 250px; | ||
overflow-y: scroll; | ||
box-shadow: $shadow; | ||
border-radius: 8px; | ||
transform-origin: top; | ||
opacity: 0; | ||
transform: scaleY(0); | ||
background-color: $white-color; | ||
transition: all $animation-duration $cubic-bezier; | ||
display: flex; | ||
.nothing-img-container { | ||
margin: 15px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-direction: column; | ||
img { | ||
width: 160px; | ||
} | ||
} | ||
&.show { | ||
opacity: 1; | ||
transform: scaleY(1); | ||
} | ||
.option-item { | ||
flex-shrink: 0; | ||
height: 35px; | ||
display: flex; | ||
align-items: center; | ||
transition: all $animation-duration $cubic-bezier; | ||
&:hover { | ||
background-color: rgba(var(--shadow-color-rgb), 0.08); | ||
padding: 0 0 0 2px; | ||
@include select-option(); | ||
} | ||
&.option-item-selected { | ||
background-color: rgba(var(--shadow-color-rgb), 0.15); | ||
padding: 0 0 0 4px; | ||
@include select-option(); | ||
} | ||
.option-item-span { | ||
padding: 0 7px; | ||
} | ||
} | ||
} | ||
|
||
@keyframes scaleFromBottom { | ||
0% { | ||
transform: scaleY(0); | ||
transform-origin: bottom; | ||
} | ||
100% { | ||
transform: scaleY(1); | ||
transform-origin: bottom; | ||
} | ||
} |
Oops, something went wrong.