Skip to content

Commit 28e5909

Browse files
committed
feat: update colors
1 parent 293455d commit 28e5909

17 files changed

Lines changed: 209 additions & 53 deletions

File tree

apps/web/src/stories/button-group.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const color: ButtonProps['color'][] = [
1717
'warning',
1818
];
1919
const sizes: ButtonProps['size'][] = ['sm', 'md', 'lg', 'xl', '2xl'];
20-
const rounded: ButtonProps['rounded'][] = ['sm', 'md', 'lg', 'xl', '2xl', '3xl', 'full'];
20+
const radius: ButtonProps['radius'][] = ['sm', 'md', 'lg', 'xl', '2xl', '3xl', 'full'];
2121

2222
const meta: Meta = {
2323
title: 'Components/Button Group',
@@ -35,8 +35,8 @@ const meta: Meta = {
3535
options: sizes,
3636
control: { type: 'select' },
3737
},
38-
rounded: {
39-
options: rounded,
38+
radius: {
39+
options: radius,
4040
control: { type: 'select' },
4141
},
4242
disabled: {

apps/web/src/stories/layout.stories.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import Link from 'next/link';
33
import type { Meta, StoryFn } from '@storybook/react';
4-
import { CalendarIcon, Layout, Sidebar } from '@var-ui/core';
4+
import { CalendarIcon, HStack, Layout, Sidebar } from '@var-ui/core';
55
import {
66
Award01Icon,
77
CoinsStacked03Icon,
@@ -211,9 +211,10 @@ const links = [
211211

212212
const DefaultTemplate: StoryFn<typeof Layout> = ({ ...args }) => {
213213
return (
214-
<div className="bg-background border-border relative min-h-[50vh] border">
215-
<Layout>
216-
<Sidebar {...args}>
214+
<div className="bg-background border-border relative min-h-[80vh] border">
215+
<Layout {...args}>
216+
<Sidebar.Overlay />
217+
<Sidebar>
217218
<Sidebar.Head>
218219
<Sidebar.Head.Toggle />
219220

@@ -260,7 +261,13 @@ const DefaultTemplate: StoryFn<typeof Layout> = ({ ...args }) => {
260261
<Sidebar.Footer>Footer</Sidebar.Footer>
261262
</Sidebar>
262263

263-
<Layout.Content>Main Page</Layout.Content>
264+
<Layout.Content>
265+
<HStack className="w-full p-4" pos="apart">
266+
<p>Content</p>
267+
268+
<Layout.BurgerMenu />
269+
</HStack>
270+
</Layout.Content>
264271
</Layout>
265272
</div>
266273
);

packages/theme/src/configs/colors/theme-colors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const defaultLightColors: ThemeColors = {
1515
foreground: {
1616
DEFAULT: colors.gray[900],
1717
primary: colors.gray[900],
18-
button: colors.brand[25],
18+
button: colors.gray[25],
1919
secondary: colors.gray[500],
2020
disabled: colors.gray[300],
2121
error: colors.error[500],
@@ -64,7 +64,7 @@ export const defaultDarkColors: ThemeColors = {
6464
foreground: {
6565
DEFAULT: colors.gray[25],
6666
primary: colors.gray[25],
67-
button: colors.brand[100],
67+
button: colors.gray[100],
6868
secondary: colors.gray[500],
6969
disabled: colors.gray[700],
7070
error: colors.error[300],

packages/ui/src/components/icons/calendar-icon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const CalendarIcon = (props: SVGProps<SVGSVGElement>) => (
55
<svg width={20} height={20} viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
66
<path
77
d="M17.5 8.333h-15m10.833-6.666V5M6.667 1.667V5M6.5 18.333h7c1.4 0 2.1 0 2.635-.272a2.5 2.5 0 0 0 1.092-1.093c.273-.534.273-1.235.273-2.635v-7c0-1.4 0-2.1-.273-2.635a2.5 2.5 0 0 0-1.092-1.092c-.535-.273-1.235-.273-2.635-.273h-7c-1.4 0-2.1 0-2.635.273a2.5 2.5 0 0 0-1.093 1.092C2.5 5.233 2.5 5.933 2.5 7.333v7c0 1.4 0 2.1.272 2.635a2.5 2.5 0 0 0 1.093 1.093c.535.272 1.235.272 2.635.272Z"
8-
stroke="#344054"
8+
stroke="currentColor"
99
strokeWidth={1.667}
1010
strokeLinecap="round"
1111
strokeLinejoin="round"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { forwardRef, useMemo, type ElementRef } from 'react';
2+
import { composeEventHandlers } from '@radix-ui/primitive';
3+
4+
import { type ElementProps } from '../../types';
5+
import { cn } from '../../utils/cn';
6+
import { useSidebarContext } from './sidebar.context';
7+
8+
const BurgerMenu = forwardRef<ElementRef<'button'>, ElementProps<'button'>>(
9+
({ children, className, onClick, ...props }, ref) => {
10+
const { open, isMobile, toggleOpen } = useSidebarContext();
11+
12+
if (!isMobile) return null;
13+
return (
14+
<button
15+
onClick={composeEventHandlers(toggleOpen, onClick)}
16+
className={cn('relative h-8 w-8', className)}
17+
{...props}
18+
ref={ref}
19+
>
20+
<div
21+
className={cn(
22+
[
23+
'bg-foreground h-px w-6 transition-transform duration-200 ease-[cubic-bezier(.55,.055,.675,.19)]',
24+
"before:contents-[''] before:bg-foreground before:absolute before:top-2 before:block before:h-px before:w-6 before:transition-[opacity,top]",
25+
"after:contents-[''] after:bg-foreground after:absolute after:bottom-2 after:block after:h-px after:w-6 after:transition-[transform,bottom] after:ease-[cubic-bezier(.215,.61,.355,1)]",
26+
],
27+
{
28+
'rotate-[225deg] before:top-0 before:opacity-0 after:bottom-0 after:-rotate-90': open,
29+
}
30+
)}
31+
/>
32+
</button>
33+
);
34+
}
35+
);
36+
37+
export { BurgerMenu };
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
import { Overlay } from '../dialog';
2+
import { BurgerMenu } from './burger-menu';
13
import { default as BaseLayout, type LayoutProps } from './layout';
24
import { MainContent } from './main-content';
35
import { default as SidebarRoot, type SidebarProps } from './sidebar';
46
import { SidebarBody, type SidebarNavListDropdownProps, type SidebarNavListItemProps } from './sidebar-body';
57
import { SidebarFooter, type SidebarFooterProps } from './sidebar-footer';
68
import { SidebarHead, type SidebarHeaderProps } from './sidebar-head';
9+
import { SidebarOverlay, type SidebarOverlayProps } from './sidebar-overlay';
710

811
export { default as SidebarProvider, type SidebarProviderProps } from './sidebar-provider';
912

10-
export const Sidebar = Object.assign(SidebarRoot, { Body: SidebarBody, Footer: SidebarFooter, Head: SidebarHead });
11-
export const Layout = Object.assign(BaseLayout, { Content: MainContent });
13+
export const Sidebar = Object.assign(SidebarRoot, {
14+
Overlay: SidebarOverlay,
15+
Body: SidebarBody,
16+
Footer: SidebarFooter,
17+
Head: SidebarHead,
18+
});
19+
export const Layout = Object.assign(BaseLayout, { Content: MainContent, BurgerMenu });
1220

1321
export type {
1422
SidebarProps,
@@ -17,4 +25,5 @@ export type {
1725
SidebarNavListItemProps,
1826
SidebarNavListDropdownProps,
1927
LayoutProps,
28+
SidebarOverlayProps,
2029
};

packages/ui/src/components/layout/layout.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, type CSSProperties, type PropsWithChildren } from 'react';
22
import { useControllableState } from '@radix-ui/react-use-controllable-state';
33

4+
import { useMediaQuery } from '../../hooks';
45
import { type VisibleState } from '../../types';
56
import { SidebarProvider as BaseSidebarProvider } from './sidebar.context';
67

@@ -10,20 +11,27 @@ export interface LayoutProps extends VisibleState {
1011
active?: string;
1112
defaultActive?: string;
1213
onActiveChange?: (active: string) => void;
14+
15+
/** Hide the sidebar when hit this breakpoint
16+
* @default '48rem'
17+
*/
18+
breakpoint?: string;
1319
}
1420

1521
const Layout = (props: PropsWithChildren<LayoutProps>) => {
1622
const {
1723
open: openProps,
18-
defaultOpen,
24+
defaultOpen = false,
1925
onOpenChange,
2026
children,
2127
active: activeProp,
2228
defaultActive: defaultActiveProp,
2329
onActiveChange,
2430
expandOnHover,
2531
sidebarWidth = 272,
32+
breakpoint = '48rem',
2633
} = props;
34+
const isMobile = useMediaQuery(`(max-width: ${breakpoint})`);
2735

2836
const [isHover, setIsHover] = useState(false);
2937

@@ -49,7 +57,8 @@ const Layout = (props: PropsWithChildren<LayoutProps>) => {
4957
<BaseSidebarProvider
5058
value={{
5159
open,
52-
isExpanded,
60+
// * On mobile - default is expanded
61+
isExpanded: isMobile ? true : isExpanded,
5362
active,
5463
setActive,
5564
toggleOpen,
@@ -58,6 +67,7 @@ const Layout = (props: PropsWithChildren<LayoutProps>) => {
5867
expandOnHover,
5968
isHover,
6069
setOpen,
70+
isMobile,
6171
}}
6272
>
6373
<div

packages/ui/src/components/layout/main-content.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { forwardRef, type ElementRef } from 'react';
1+
import { forwardRef, useMemo, type ElementRef } from 'react';
22

33
import { type ElementProps } from '../../types';
44
import { useSidebarContext } from './sidebar.context';
55

66
const MainContent = forwardRef<ElementRef<'main'>, ElementProps<'main'>>(({ children, className, ...props }, ref) => {
7-
const { isExpanded, sidebarWidth } = useSidebarContext();
7+
const { isExpanded, sidebarWidth, isMobile } = useSidebarContext();
8+
9+
const marginLeft = useMemo(() => {
10+
if (isMobile) return undefined;
11+
return isExpanded ? sidebarWidth : 80;
12+
}, [isExpanded, isMobile, sidebarWidth]);
13+
814
return (
9-
<main style={{ marginLeft: isExpanded ? sidebarWidth : 80 }} className={className} {...props} ref={ref}>
15+
<main style={{ marginLeft }} className={className} {...props} ref={ref}>
1016
{children}
1117
</main>
1218
);

packages/ui/src/components/layout/sidebar-head.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ const SidebarHeader = forwardRef<ElementRef<'div'>, SidebarHeaderProps>(
4141
);
4242

4343
const SidebarToggle = forwardRef<ElementRef<typeof Button>, ButtonProps>(({ children, onClick, ...props }, ref) => {
44-
const { open, toggleOpen } = useSidebarContext();
44+
const { open, toggleOpen, isMobile } = useSidebarContext();
4545

46+
if (isMobile) return null;
4647
return (
4748
<Button
4849
onClick={composeEventHandlers(onClick, toggleOpen)}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as React from 'react';
2+
import { Portal as PortalPrimitive, type PortalProps } from '@radix-ui/react-portal';
3+
import { Presence } from '@radix-ui/react-presence';
4+
import type * as Radix from '@radix-ui/react-primitive';
5+
import { Primitive } from '@radix-ui/react-primitive';
6+
7+
import { cn } from '../../utils/cn';
8+
import { composeEventHandlers } from '../../utils/compose-event-handler';
9+
import { withAttr } from '../../utils/withAttr';
10+
import { useSidebarContext } from './sidebar.context';
11+
12+
type SidebarOverlayImplElement = React.ElementRef<typeof Primitive.div>;
13+
type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
14+
interface SidebarOverlayImplProps extends PrimitiveDivProps {}
15+
16+
const SidebarOverlayImpl = React.forwardRef<SidebarOverlayImplElement, SidebarOverlayImplProps>(
17+
(props: SidebarOverlayImplProps, forwardedRef) => {
18+
const { open, setOpen } = useSidebarContext();
19+
return (
20+
<Primitive.div
21+
role="sidebar-overlay"
22+
data-state={withAttr(open)}
23+
{...props}
24+
ref={forwardedRef}
25+
style={{ pointerEvents: open ? 'auto' : 'none', ...props.style }}
26+
onClick={composeEventHandlers(props.onClick, (e: any) => {
27+
if (e.target['ariaHidden'] === 'true') return;
28+
setOpen(false);
29+
})}
30+
/>
31+
);
32+
}
33+
);
34+
35+
const OVERLAY_NAME = 'SidebarOverlay';
36+
37+
type SidebarOverlayElement = SidebarOverlayImplElement;
38+
export interface SidebarOverlayProps extends SidebarOverlayImplProps {
39+
/**
40+
* Specify a container element to portal the content into.
41+
*/
42+
container?: PortalProps['container'];
43+
/**
44+
* Used to force mounting when more control is needed. Useful when
45+
* controlling animation with React animation libraries.
46+
*/
47+
forceMount?: true;
48+
}
49+
50+
export const SidebarOverlay = React.forwardRef<SidebarOverlayElement, SidebarOverlayProps>(
51+
(props: SidebarOverlayProps, forwardedRef) => {
52+
const { forceMount, className, container, ...etc } = props;
53+
const { open, isMobile } = useSidebarContext();
54+
if (!isMobile) return null;
55+
56+
return (
57+
<SidebarOverlayImpl
58+
className={cn(
59+
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 bg-background/70 fixed inset-0 z-40 backdrop-blur-sm transition-all',
60+
{
61+
'invisible opacity-0': !open,
62+
'visible opacity-100': open,
63+
},
64+
className
65+
)}
66+
{...etc}
67+
ref={forwardedRef}
68+
/>
69+
);
70+
}
71+
);
72+
73+
SidebarOverlay.displayName = OVERLAY_NAME;

0 commit comments

Comments
 (0)