Comments (6)
Sorry, I should have been more clear.
I'm looking to share styling between classes, within the context of a single createUseClassNames
call.
In the example above, I want a link's :hover
state to look the same as its react router activeClassName
state.
With JSS, there exists the extend plugin: https://cssinjs.org/jss-plugin-extend/
The best plan I've come up with for this would be an external function that's called with theme/props.
So, to rework the example above:
const helper = (theme, props) => ({
// shared style that relies on theme and/or props
});
const { useClassNames } = createUseClassNames<Props>()((theme, props) => ({
link: {
// other styles
'&:hover': helper(theme, props),
},
activeLink: helper(theme, props),
}));
Hopefully this makes sense.
Also, this is definitely more of a nice to have, considering there's a workaround.
I figured it was in-line with your projects goals though.
from tss-react.
@awdyson This is actually a very good point, we need to support that.
Very easy to implement but hard to type.
I will try to think of something...
from tss-react.
Haven't been able to work on this project in a while, so I'm catching up on a lot of updates.
Your solution looks great -- and is the sort of thing I couldn't do well in JSS+MUI for a reason I can't remember.
Also, the method and property names look a lot cleaner these days.
Appreciate the great work 😃
from tss-react.
Sorry for late reply @awdyson ,
Sure you can it's a very important requirement!
type Props ={
size: "big" | "small";
};
const { useClassNames } = createUseClassNames<Props & { color: "red" | "blue" }>()(
(theme, { size, color }) => ({
link: {
...
'&:hover': {
extend: 'activeLink', // JSS solution
},
},
activeLink: {
// Here you have access to "size" from Props and "color" from internal state
},
}));
function MyComponent(props: Props){
const [ color, setColor ] = useState<"red" | "blue">("red");
const { classNames } = useClassNames({ ...props, color });
//...
}
Best regard
from tss-react.
I will, soon, implement something like that:
const { classes, getLinkCss } = makeStyles<Props>()(
(theme, props) => ({
"link": {
// other styles
"&:hover": {
//style specific to hover link
},
},
"activeLink": {
...getLinkCss(theme, props)["&:hover"],
//style specific to activeLink
}
})
);
//getLinkCss can be exported for reuse outside of the file.
export { getLinkCss };
We'll get correct typing of getLinkCss
, getActiveLinkCss
using template literal types.
There will be some voodoo involved to prevent infinite recursion behind the seen but it will be transparent to the user.
from tss-react.
In the end I figured out that there is no need for a dedicated API.
Composition documentation
from tss-react.
Related Issues (20)
- Import module error with Vite JS HOT 9
- lint errors with 4.8 but not with 4.7.7 HOT 2
- MUI styles overriding Tss react styles while upgrading to MUI v5 HOT 11
- Mixing multiple classes with nested selectors can lead to undesired output HOT 1
- eslint-plugin-tss-unused-classes detects every class as unused HOT 1
- Missing classname escaping HOT 1
- FOUC when using NextAppDirEmotionCacheProvider with prepend true HOT 8
- How to opt out of RTL transformation? HOT 3
- <GlobalStyles /> don't work properly with next.js app folder HOT 7
- cannot Import multiple makeStyles HOT 1
- Use eslint rule to detect unused classed with imports HOT 2
- React 16.10.0 failed to install @ mui/material HOT 1
- How to use with css and styled apis. HOT 1
- yarn install with pnp mode complains about missing dependency @mui/material HOT 3
- NextJS/MUI/TSS - Cannot read properties of undefined (reading 'classes') HOT 3
- Hard reload after any file change HOT 2
- TssCacheProvider is not working when used with emotion cache and mui 5 HOT 6
- Using with Shadowed Web Components HOT 3
- Next.js: Applying augmentDocumentWithEmotionCache to document breaks AMP pages HOT 2
- The right way typing props when using withStyles HOT 3
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 tss-react.