feat(WEB-170): edit profile view
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
"use client"
|
||||
import { useEffect, useRef, useState, type FocusEvent } from "react"
|
||||
|
||||
import {
|
||||
Button,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
Popover,
|
||||
Select as ReactAriaSelect,
|
||||
SelectValue,
|
||||
type Key,
|
||||
} from "react-aria-components"
|
||||
import SelectChevron from "../../SelectChevron"
|
||||
|
||||
import styles from "./select.module.css"
|
||||
|
||||
import type { SelectProps } from "./select"
|
||||
|
||||
export default function Select({
|
||||
items,
|
||||
label,
|
||||
name,
|
||||
onSelect,
|
||||
placeholder,
|
||||
value,
|
||||
}: SelectProps) {
|
||||
const divRef = useRef<HTMLDivElement>(null)
|
||||
const [divElement, setDivElement] = useState(divRef.current)
|
||||
|
||||
function handleOnSelect(key: Key) {
|
||||
onSelect(key, name)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (divRef.current) {
|
||||
setDivElement(divRef.current)
|
||||
}
|
||||
}, [divRef.current])
|
||||
|
||||
return (
|
||||
<div className={styles.date} ref={divRef}>
|
||||
<ReactAriaSelect
|
||||
className={styles.select}
|
||||
onSelectionChange={handleOnSelect}
|
||||
placeholder={placeholder}
|
||||
selectedKey={value as Key}
|
||||
>
|
||||
<Label className={styles.label}>{label}</Label>
|
||||
<Button className={styles.input}>
|
||||
<SelectValue />
|
||||
<SelectChevron />
|
||||
</Button>
|
||||
<Popover
|
||||
className={styles.popover}
|
||||
placement="bottom"
|
||||
shouldFlip={false}
|
||||
/**
|
||||
* react-aria uses portals to render Popover in body
|
||||
* unless otherwise specified. We need it to be contained
|
||||
* by this component to both access css variables assigned
|
||||
* on the container as well as to not overflow it at any time.
|
||||
*/
|
||||
UNSTABLE_portalContainer={divElement ?? undefined}
|
||||
>
|
||||
<ListBox className={styles.listBox}>
|
||||
{items.map((item) => (
|
||||
<ListBoxItem
|
||||
key={item}
|
||||
className={styles.listBoxItem}
|
||||
id={item}
|
||||
textValue={String(item)}
|
||||
>
|
||||
{item}
|
||||
</ListBoxItem>
|
||||
))}
|
||||
</ListBox>
|
||||
</Popover>
|
||||
</ReactAriaSelect>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
.date {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-family: var(--ff-fira-sans);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.select {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.input {
|
||||
align-items: center;
|
||||
background-color: var(--some-white-color, #fff);
|
||||
border: var(--border);
|
||||
border-radius: var(--radius);
|
||||
color: var(--some-black-color, #757575);
|
||||
display: grid;
|
||||
font-family: var(--ff-fira-sans);
|
||||
font-size: 1.6rem;
|
||||
font-weight: 400;
|
||||
gap: 1rem;
|
||||
grid-template-columns: 1fr auto;
|
||||
height: 4rem;
|
||||
letter-spacing: -1.5%;
|
||||
line-height: 2.4rem;
|
||||
padding: 0.8rem 1rem 0.8rem 1.6rem;
|
||||
}
|
||||
|
||||
.popover {
|
||||
background-color: var(--some-white-color, #fff);
|
||||
border: var(--border);
|
||||
border-radius: var(--radius);
|
||||
overflow: auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.listBox {
|
||||
padding: 1.6rem 1.6rem 1.6rem 0.8rem;
|
||||
}
|
||||
|
||||
.listBoxItem {
|
||||
padding: 0 0.8rem;
|
||||
}
|
||||
|
||||
.listBoxItem[data-selected="true"],
|
||||
.listBoxItem[data-focused="true"] {
|
||||
background-color: rgba(75, 75, 75, 0.2);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { Key } from "react-aria-components"
|
||||
|
||||
export const enum DateName {
|
||||
date = "date",
|
||||
month = "month",
|
||||
year = "year",
|
||||
}
|
||||
|
||||
export interface SelectProps
|
||||
extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, "onSelect"> {
|
||||
items: number[]
|
||||
label: string
|
||||
name: DateName
|
||||
onSelect: (key: Key, name: DateName) => void
|
||||
placeholder?: string
|
||||
}
|
||||
Reference in New Issue
Block a user