Comments (4)
I was imagining a way to generalize this kind of functionality. I can think of dark mode and media queries as modifiers to a class name. Tailwind uses this idea and denotes the modifier by using a colon after the modifier: https://tailwindcss.com/docs/hover-focus-and-other-states e.g., dark:active:sm:bg-red-300
. Since a colon is already used in zephyr maybe it could be replaced with the pipe character: dark|active|sm|bg:red-300
. If such a scheme was adopted you would probably need to introduce modifier filter functions
{
modifierFilters: {
dark: (styleState) => styleState.darkMode,
mq: {
sm: (styleState) => styleState.viewportWidth >= 300,
md: (styleState) => styleState.viewportWidth >= 600,
lg: (styleState) => styleState.viewportWidth >= 800,
},
active: (styleState) => styleState.active
}
}
here styleState could be provided to the useStyle hook as a second argument (with defaults provided by state context.
const styles = useStyles([
"flex:1",
"bg:red-300",
"active|bg-red-500",
"dark|bg:red-900",
"dark|active|bg-red-600",
"p:1",
"mq:sm|p:2"
"mq:md|p:3"
"mq:lg|px:6",
"mq:lg|py:4"
], {
darkMode: true, // force dark mode (normal scenario this would not be provided here and would be pulled from context)
viewportWidth: 600, // force a certain viewportWidth (normally would not be provided and pulled from context instead
active: true // potentially provided by wrapping pressable or props
});
return <View style={styles} />;
I totally understand if this is not the sort of api you want. It's just what I had in mind when I made the issue.
from react-native-zephyr.
Okay, so here's what I'm thinking for an API:
const { useStyles } = createStyleBuilder({
// Define your breakpoints (and prefixes) when configuring your builder
breakpoints: {
sm: 300,
md: 450,
lg: 700
}
});
// Apply them...
const MyComponent = () => {
const wrapperStyles = useStlyes({
classes: ["flex:1", "bg:red-300", "p:1"],
darkClasses: ["bg:red-900"],
smClasses: ["p:2"],
mdClasses: ["p:3"],
lgClasses: ["px:6", "py:4"]
});
return <View style={wrapperStyles} />;
}
Basically,
- Define breakpoints in your builder configuration.
- Then, Zephyr will expose additional
*Classes
fields for you to pass in classes to be applied when viewport width greater than specified breakpoint values. - Under the hood, Zephyr will apply those classes accordingly based on viewport width.
from react-native-zephyr.
Any news on this one? It's the only missing feature that will get Restyle to the back bench 🥇
from react-native-zephyr.
I think this is a fantastic idea! I think that, similar to dark mode, we could setup a top-level screen size listener (in the StyleProvider), and use that to apply styles based on configurable breakpoints. I think this is very doable, and wouldn't be too complex -- just need to workshop on what the api would look like! (How/where we want to configure the breakpoints, how we want to specify classes per breakpoint, etc)
If you're interested in contributing, I'd be happy to work on this with you! Otherwise we can file this as an "enhancement" ticket, and get to this in the near future.
from react-native-zephyr.
Related Issues (17)
- Feature: letter-spacing (tracking) support HOT 1
- Feature: line-height (leading) classes HOT 1
- Feature: Text Shadow
- Feature: Support different base font size for default classes HOT 1
- Docs: add sample of extended color palette
- Memoize `makeStyledComponent` wrapped component HOT 5
- Docs: No GitHub link on mobile. HOT 1
- Feature: `styled` helper, similar to Styled Components HOT 1
- Types cleanup: `createStyleBuilder.test.tsx` mock types
- Add caching to CI jobs
- Bug: Support opacity-provided color strings like `rgba(0,0,0,0)` and `#ffffffff`. HOT 1
- Web support? HOT 2
- Add Ability to override fontFamily ?
- [Question] Why array instead of string? HOT 1
- Feature: gap, colGap, rowGap
- [Not an issue, the opposite actually] Performance benchmarks 🌟
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-zephyr.