feat: add initial design to Select
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { useRef } from "react"
|
import { RefObject, useEffect, useRef, useState } from "react"
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
type Key,
|
type Key,
|
||||||
@@ -21,20 +21,23 @@ export default function Select({
|
|||||||
"aria-label": ariaLabel,
|
"aria-label": ariaLabel,
|
||||||
items,
|
items,
|
||||||
label,
|
label,
|
||||||
name,
|
// name,
|
||||||
onSelect,
|
onSelect,
|
||||||
placeholder,
|
placeholder,
|
||||||
value,
|
value,
|
||||||
defaultSelectedKey,
|
defaultSelectedKey,
|
||||||
}: SelectProps) {
|
}: SelectProps) {
|
||||||
const divRef = useRef<HTMLDivElement>(null)
|
const ref = useRef<HTMLDivElement>(null)
|
||||||
|
const [rootDiv, setRootDiv] = useState<HTMLDivElement | null>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
setRootDiv(ref.current)
|
||||||
|
}, [ref])
|
||||||
function handleOnSelect(key: Key) {
|
function handleOnSelect(key: Key) {
|
||||||
onSelect(key)
|
onSelect(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.date} ref={divRef}>
|
<div className={styles.container} ref={ref}>
|
||||||
<ReactAriaSelect
|
<ReactAriaSelect
|
||||||
defaultSelectedKey={defaultSelectedKey}
|
defaultSelectedKey={defaultSelectedKey}
|
||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
@@ -43,9 +46,11 @@ export default function Select({
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
selectedKey={value as Key}
|
selectedKey={value as Key}
|
||||||
>
|
>
|
||||||
<Label className={styles.label}>{label}</Label>
|
|
||||||
<Button className={styles.input}>
|
<Button className={styles.input}>
|
||||||
<SelectValue />
|
<div className={styles.inputContentWrapper}>
|
||||||
|
<Label className={styles.label}>{label}</Label>
|
||||||
|
<SelectValue />
|
||||||
|
</div>
|
||||||
<SelectChevron />
|
<SelectChevron />
|
||||||
</Button>
|
</Button>
|
||||||
<Popover
|
<Popover
|
||||||
@@ -58,7 +63,7 @@ export default function Select({
|
|||||||
* by this component to both access css variables assigned
|
* by this component to both access css variables assigned
|
||||||
* on the container as well as to not overflow it at any time.
|
* on the container as well as to not overflow it at any time.
|
||||||
*/
|
*/
|
||||||
UNSTABLE_portalContainer={divRef.current ?? undefined}
|
UNSTABLE_portalContainer={rootDiv ?? undefined}
|
||||||
>
|
>
|
||||||
<ListBox className={styles.listBox}>
|
<ListBox className={styles.listBox}>
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.date {
|
.container {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,51 +7,76 @@
|
|||||||
font-family: var(--typography-Footnote-Regular-fontFamily);
|
font-family: var(--typography-Footnote-Regular-fontFamily);
|
||||||
font-size: var(--typography-Footnote-Regular-fontSize);
|
font-size: var(--typography-Footnote-Regular-fontSize);
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
position: absolute;
|
line-height: 100%;
|
||||||
left: 1.6rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.select {
|
.select {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.4rem;
|
gap: 0.4rem;
|
||||||
|
border: 1px solid var(--Base-Border-Normal);
|
||||||
|
border-radius: var(--Corner-radius-Medium);
|
||||||
|
}
|
||||||
|
|
||||||
|
.select[data-focused="true"] {
|
||||||
|
border: 1px solid var(--UI-Text-Active, #0d1f5f);
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
align-items: end;
|
display: flex;
|
||||||
background-color: var(--some-white-color, #fff);
|
align-items: center;
|
||||||
border: 1px solid var(--Base-Input-Controls-Border-Normal, #b8a79a);
|
gap: 0.4rem;
|
||||||
border-radius: 0.8rem;
|
background-color: var(--Scandic-Opacity-White-100);
|
||||||
color: var(--some-black-color, #757575);
|
border: none;
|
||||||
display: grid;
|
border-radius: var(--Corner-radius-Medium);
|
||||||
font-family: var(--typography-Body-Regular-fontFamily);
|
color: var(--Base-Text-UI-High-contrast);
|
||||||
|
height: 5.6rem;
|
||||||
|
font-family: var(--ff-fira-sans);
|
||||||
font-size: 1.6rem;
|
font-size: 1.6rem;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
gap: 1rem;
|
letter-spacing: var(--typography-Body-Regular-letterSpacing);
|
||||||
grid-template-columns: 1fr auto;
|
line-height: 100%;
|
||||||
height: 5.6rem;
|
outline: none;
|
||||||
/* letter-spacing: -1.5%; */
|
padding: var(--Spacing-x-one-and-half) var(--Spacing-x2);
|
||||||
line-height: 2.4rem;
|
text-align: left;
|
||||||
padding: 0.8rem 1.6rem;
|
}
|
||||||
|
|
||||||
|
.inputContentWrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.6rem;
|
||||||
|
flex: 1 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.popover {
|
.popover {
|
||||||
background-color: var(--some-white-color, #fff);
|
background-color: var(--some-white-color, #fff);
|
||||||
border: var(--border);
|
border-radius: var(--Corner-radius-Medium);
|
||||||
border-radius: var(--radius);
|
display: inline-flex;
|
||||||
|
flex-direction: column;
|
||||||
|
font-size: var(--typography-Body-Regular-fontSize);
|
||||||
|
gap: var(--Spacing-x1);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
box-shadow: 0px 4px 24px 0px rgba(0, 0, 0, 0.08);
|
||||||
}
|
}
|
||||||
|
|
||||||
.listBox {
|
.listBox {
|
||||||
padding: 1.6rem 1.6rem 1.6rem 0.8rem;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--Spacing-x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.listBoxItem {
|
.listBoxItem {
|
||||||
padding: 0 0.8rem;
|
padding: var(--Spacing-x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.listBoxItem[data-selected="true"],
|
|
||||||
.listBoxItem[data-focused="true"] {
|
.listBoxItem[data-focused="true"] {
|
||||||
background-color: rgba(75, 75, 75, 0.2);
|
background: var(--UI-Input-Controls-Surface-Hover, var(--Scandic-Blue-00));
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listBoxItem[data-selected="true"] {
|
||||||
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user