Skip to content

Commit

Permalink
added radix ui scroll area to make scroll height capped, small add ti…
Browse files Browse the repository at this point in the history
…me edits
  • Loading branch information
jxmoose committed Dec 3, 2024
1 parent 6ec3dfd commit 462b373
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 21 deletions.
4 changes: 2 additions & 2 deletions components/DateTimeSelection/DateTimeSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AddTime, Bar, Container, TimeList, Times } from './styles';

export default function DateTimeSelection({ date }: { date: Date }) {
const [timeList, setTimeList] = useState([
<Times>
<Times key={0}>
{/* initialize at 9 am / 5 pm */}
<TimeSelection minutes={9 * 60} />
<H6 $color={COLORS.gray8}> - </H6>
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function DateTimeSelection({ date }: { date: Date }) {
</H6>
<Bar />
<TimeList> {timeList}</TimeList>
<AddTime onClick={() => onAddBtnClick}>
<AddTime onClick={() => onAddBtnClick()}>
<SMALL $color={COLORS.lilac8} $fontWeight={400}>
add time
</SMALL>
Expand Down
3 changes: 2 additions & 1 deletion components/DateTimeSelection/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const Times = styled.div`

export const AddTime = styled.button`
all: unset;
margin-top: 1rem;
padding-top: 1rem;
padding-bottom: 1rem;
`;

export const TimeList = styled.div`
Expand Down
35 changes: 21 additions & 14 deletions components/TimeSelection/TimeSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { CheckIcon, ChevronDownIcon } from '@radix-ui/react-icons';
import * as ScrollArea from '@radix-ui/react-scroll-area';
import * as Select from '@radix-ui/react-select';
import classnames from 'classnames';
import { Container, Test } from './styles';
import { Container, Content } from './styles';

export default function TimeSelection({ minutes }: { minutes: number }) {
const minutesToFormatted = (minutes: number) => {
Expand Down Expand Up @@ -37,21 +38,27 @@ export default function TimeSelection({ minutes }: { minutes: number }) {
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Test>
<Content>
<Select.Content className="SelectContent">
<Select.Viewport className="SelectViewport">
<Select.Group className="group">
{times.map(time => {
const minutes = time[0];
const formattedTime = time[1];
return (
<SelectItem value={minutes}> {formattedTime} </SelectItem>
);
})}
</Select.Group>
</Select.Viewport>
<ScrollArea.Root className="Scroll" type="auto">
<Select.Viewport asChild className="SelectViewport">
<ScrollArea.Viewport className="ScrollViewport">
<Select.Group className="group">
{times.map((time, i) => {
const minutes = time[0];
const formattedTime = time[1];
return (
<SelectItem key={i} value={minutes}>
{formattedTime}
</SelectItem>
);
})}
</Select.Group>
</ScrollArea.Viewport>
</Select.Viewport>
</ScrollArea.Root>
</Select.Content>
</Test>
</Content>
</Select.Portal>
</Select.Root>
</Container>
Expand Down
16 changes: 12 additions & 4 deletions components/TimeSelection/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@ export const Container = styled.div`
}
`;

export const Test = styled.div`
.SelectContent {
overflow: hidden;
export const Content = styled.div`
.Scroll {
overflow: scroll;
height: 200px;
background-color: white;
border: 1px solid ${COLORS.rose7};
border-radius: 8px;
height: 200px;
box-shadow:
0px 10px 38px -10px rgba(22, 23, 24, 0.35),
0px 10px 20px -15px rgba(22, 23, 24, 0.2);
}
.ScrollViewPort {
width: 100%;
height: 100%;
}
.SelectContent {
}
.SelectScrollButton {
display: flex;
align-items: center;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@next/font": "^14.2.15",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/react-scroll-area": "^1.2.1",
"@radix-ui/react-select": "^2.1.2",
"@supabase/supabase-js": "^2.45.4",
"classnames": "^2.5.1",
Expand Down
62 changes: 62 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 462b373

Please sign in to comment.