-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bop it #1441
bop it #1441
Conversation
src/view/screens/DesignSystem.tsx
Outdated
<ThemeProvider theme={themes.dark}> | ||
<Box pa="m" gtPhone={{padding: 'l'}}> | ||
<H2 as="h1" c="theme" gtPhone={{mb: 'm', marginTop: 'l'}} debug> | ||
Heading 1 | ||
</H2> | ||
<H1 as="h2" c="theme" style={{color: 'tomato'}}> | ||
Heading 2 | ||
</H1> | ||
<H3 lh="xl">Heading 3</H3> | ||
<P caps>Paragraph</P> | ||
|
||
<Box inline aic gap="m" my="l"> | ||
<Box w={100} h={100} bg="theme" /> | ||
<Box w={50} h={50} bg="text" /> | ||
<Text font="mono">Monospace</Text> | ||
</Box> | ||
</Box> | ||
</ThemeProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What it boils down to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is useStyles
being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it only meant to be used by our custom components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it just returns one styles
variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh yeah I should write a few docs to explain this idea better, will do that this morning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Themes configured here
src/lib/design-system/lib.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The library itself
src/lib/design-system/index.tsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically the components portion of the library
m: 16, | ||
l: 24, | ||
}, | ||
color: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. We probably want to add the colors from the existing theme.ts
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we'd need to bike shed some naming and stuff too
I think we're as close to Tamagui as we can get without getting our eyes wet. We're at a point where we should have a closer look at it as an option, and only come back here if new concerns arise. Atm the only cons I can think of around using Tamagui is that it's a little more of an all-or-nothing approach (can still do incrementally), and may not be as smooth of a transition going from Closing for now! |
Update: refactored the
ToggleButton
as an example, see latest commit.This PR is based around a hook that can be used in various situations.
I also want to highlight the intellisense available on
Box
andText
, but also withinuseStyle
and other utils.useStyle
The goal here was a mid-level (as opposed to low (like
theme.style
or high-level (likeBox
)) util that can be used for defining more complex components like a button, or for styling 3rd party libraries.It accepts any style props configured by us via
properties
on the theme.So like for a button, we could make a component like this (this is rough):
Similarly for a 3rd party component like a dropdown or something:
I also added (as an example) what a more familiar (like
StyleSheet.create
) pattern could look like withuseStyles
(plural, formerlyuseMultiStyle
):Which gives nice intellisense.
So otherwise, typical usage as primitive components looks like this:
Main things to note from this example
Properties can be longhand or shorthand, whatever we configure. These could even match like, Tailwind or something if we wanted.
Properties apply in-order, and override just like a normal object i.e. both of the following will result in
backgroundColor: 'dark'
gtPhone
is a breakpoint, which is only applied above the value configured in the theme. We can name these anything we want, I just took a page from Tamagui's book for this convention. We can have multiple breakpoints. They only update and re-render when the browser window crosses the threshold of a new breakpoint. I also designed this in a way that we should be able to just disable breakpoints on mobile/tablet and basically apply whatever screen size the device has, then never update again (may not want this if we aim to support landscape orientation too, but just thinking ahead).Most properties can also accept non-theme values, like
padding
above falls back toDimensionValue
from RN.Properties defined as
macros
can be boolean, meaning no need to pass a value i.e.inline
above that applies{ flexDirection: row }
Theming stuff
Themes are created using a factory function. The idea here was just to create types based on what's passed in instead of extending a namespace like some other libraries. Little easier to reason about.
tokens
are "design tokens" and correspond to their CSS property names, with the exception ofspace
, which is manually mapped to properties usingspecialTokenMapping
here. There are a few properties mapped tocolor
tokens as well, likebackgroundColor
andborderColor
, etc. Otherwise stuff likefontSize
corresponds directly tofontSize
property definitions on components.properties
on the theme includes all valid CSS properties by default, and as you can see we can extend them to include "aliases" or "shorthands".macros
are basically custom props. Pass in a value and return a style object. They're useful for boolean attributes, likeinline
above. But also good for stuff likefont
that needs to apply a different font family depending onfontFamily
andfontWeight
attributes i.e. we could pass in likefont='sans bold'
and map that to{ fontFamily: 'InterBold' }
.Ideas
Values like '100vh' work on web but not mobile, so we should export a util like
web('100vh')
that tells TypeScript that it's valid and prevents that value from being applied if outside a web env.useStyle
could accept a function which gets passed the wholetheme
object or something too if we want to access it or thetokens
within it.