-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
197 additions
and
11 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
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,5 @@ | ||
import { sidebar } from './styles.css.ts' | ||
|
||
export function Sidebar() { | ||
return <div className={sidebar}></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { style } from '@vanilla-extract/css' | ||
|
||
export const sidebar = style({ | ||
width: '4rem', | ||
position: 'relative', | ||
}) |
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import '&theme/preflight.css.ts' | ||
import '&theme/provider.tsx' | ||
import '&theme/preflight.css.ts' | ||
import '&theme/provider.tsx' | ||
|
||
import { Button } from '&ui/button' | ||
import { Sidebar } from '&fragments/window/sidebar' | ||
import { Box } from '&ui/layout' | ||
import { Row } from '&ui/layout' | ||
|
||
export function Root() { | ||
return <Button style={{ margin: '50px' }}>Launch</Button> | ||
return ( | ||
<Row> | ||
<Sidebar /> | ||
<Box bg='background' roundedLeft='m'> | ||
{/* TODO */} | ||
</Box> | ||
</Row> | ||
) | ||
} |
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,31 @@ | ||
const { entries } = Object | ||
|
||
export type Leaves<T> = T extends object | ||
? { [K in keyof T]: `${Exclude<K, symbol>}${Leaves<T[K]> extends never ? '' : `.${Leaves<T[K]>}`}` }[keyof T] | ||
: never | ||
|
||
type PathAccess<T, P extends string> = P extends `${infer K}.${infer R}` | ||
? K extends keyof T | ||
? PathAccess<T[K], R> | ||
: never | ||
: P extends keyof T | ||
? T[P] | ||
: never | ||
|
||
export function leaves<T extends object>(target: T, prefix: string[] = []): Leaves<T>[] { | ||
const list = [] | ||
|
||
for (const [key, value] of entries(target)) { | ||
if (typeof value === 'object') { | ||
list.push(...leaves(value, [...prefix, key])) | ||
} else { | ||
list.push([...prefix, key].join('.')) | ||
} | ||
} | ||
|
||
return list as Leaves<T>[] | ||
} | ||
|
||
export function pathAccess<T extends object, P extends Leaves<T>>(target: T, path: P) { | ||
return path.split('.').reduce((a, c) => Reflect.get(a as object, c), target) as PathAccess<T, P> | ||
} |
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
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,26 @@ | ||
import { clsx } from 'clsx' | ||
|
||
import type { LayoutProps } from './shared.ts' | ||
import { useStyle } from './shared.ts' | ||
import { box } from './styles.css.ts' | ||
import { col } from './styles.css.ts' | ||
import { row } from './styles.css.ts' | ||
|
||
export function Row(props: LayoutProps) { | ||
const { style, rest } = useStyle(props) | ||
return <div {...rest} className={clsx(row, style)} /> | ||
} | ||
|
||
export function Col(props: LayoutProps) { | ||
const { style, rest } = useStyle(props) | ||
return <div {...rest} className={clsx(col, style)} /> | ||
} | ||
|
||
export type BoxProps = Omit<LayoutProps, 'gap' | 'grow'> | ||
|
||
export function Box(props: BoxProps) { | ||
const { style, rest } = useStyle(props) | ||
return <div {...rest} className={clsx(box, style)} /> | ||
} | ||
|
||
export type { LayoutProps } |
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,32 @@ | ||
import type { ComponentProps } from 'react' | ||
|
||
import { clsx } from 'clsx' | ||
|
||
import type { Leaves } from '&shared/nanolib.ts' | ||
import type { vars } from '&theme/vars.css.ts' | ||
import { variants } from '&ui/layout/styles.css.ts' | ||
|
||
export type LayoutProps = ComponentProps<'div'> & { | ||
gap?: keyof typeof vars.space | ||
p?: keyof typeof vars.space | ||
bg?: Leaves<typeof vars.color> | ||
rounded?: keyof typeof vars.rounded | ||
roundedLeft?: keyof typeof vars.rounded | ||
grow?: boolean | ||
} | ||
|
||
export function useStyle(props: LayoutProps) { | ||
const { gap, p, bg, grow, rounded, roundedLeft, ...rest } = props | ||
|
||
return { | ||
style: clsx( | ||
gap && variants.gap[gap], | ||
p && variants.p[p], | ||
bg && variants.bg[bg], | ||
grow && variants.grow.true, | ||
rounded && variants.rounded[rounded], | ||
roundedLeft && variants.roundedLeft[roundedLeft], | ||
), | ||
rest, | ||
} | ||
} |
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,54 @@ | ||
import { style } from '@vanilla-extract/css' | ||
import { styleVariants } from '@vanilla-extract/css' | ||
|
||
import { mapVars } from '&theme/vars.css.ts' | ||
import { mapVarsPath } from '&theme/vars.css.ts' | ||
import { vars } from '&theme/vars.css.ts' | ||
|
||
const base = style({ | ||
display: 'flex', | ||
transitionProperty: 'all', | ||
transitionDuration: vars.transition.duration.m, | ||
transitionTimingFunction: vars.transition.timing, | ||
}) | ||
|
||
export const variants = { | ||
gap: styleVariants(mapVars(vars.space, (gap) => ({ gap }))), | ||
p: styleVariants(mapVars(vars.space, (padding) => ({ padding }))), | ||
bg: styleVariants(mapVarsPath(vars.color, (backgroundColor) => ({ backgroundColor }))), | ||
rounded: styleVariants(mapVars(vars.rounded, (borderRadius) => ({ borderRadius }))), | ||
roundedLeft: styleVariants( | ||
mapVars(vars.rounded, (radius) => ({ | ||
borderTopLeftRadius: radius, | ||
borderBottomLeftRadius: radius, | ||
})), | ||
), | ||
grow: styleVariants({ | ||
true: { | ||
flexGrow: 1, | ||
}, | ||
}), | ||
} | ||
|
||
export const row = style([ | ||
base, | ||
{ | ||
width: '100%', | ||
flexDirection: 'row', | ||
}, | ||
]) | ||
|
||
export const col = style([ | ||
base, | ||
{ | ||
height: '100%', | ||
flexDirection: 'column', | ||
}, | ||
]) | ||
|
||
export const box = style([ | ||
base, | ||
{ | ||
flexGrow: 1, | ||
}, | ||
]) |