-
Notifications
You must be signed in to change notification settings - Fork 63
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
Docs: Limitations & runtime styles #1553
Comments
Ah sorry for the delay. Docs are very outdated - we've been focused on quite a few internal initiatives, and so we haven't had the chance to update our external-facing docs in a while. What hasn't been documented externally yet includes stuff like our move towards object notation, a more Emotion-like API (see below example) and as you mentioned, support for dynamic variables (which we don't really recommend internally anymore 😅). Updating our documentation is definitely on our todo list though 👀 For the time being, hopefully the following code will help for your code snippet: // Object notation - what we recommend when using the styled API
export const Card = styled.span({
color: (props) => props.$color,
backgroundColor: (props) => props.color,
});
export const Text = styled.p({
fontSize: `${(props) => props.$fontsize}px`,
fontWeight: (props) => (props.level === 'h1' ? 700 : 600),
gridColumn: (props) => props.gridColumn,
margin: (props) => props.margin,
textTransform: (props) => props.textTransform,
}); // However, we currently recommend using the Emotion-like css API,
// which has many restrictions imposed on it for performance
/** @jsx jsx */
import { css, jsx } from '@compiled/react';
export const cardStyles = css({
color: (props) => props.$color,
backgroundColor: (props) => props.color,
});
export const textStyles = css({
fontSize: `${(props) => props.$fontsize}px`,
fontWeight: (props) => (props.level === 'h1' ? 700 : 600),
gridColumn: (props) => props.gridColumn,
margin: (props) => props.margin,
textTransform: (props) => props.textTransform,
});
// ...
export default function Home() {
const [value, setValue] = useState(25);
console.log(colors.primary);
return (
<span css={cardStyles}>
<input
value={value}
type="number"
onChange={(ev) => setValue(ev.target.value)}
/>
<p css={textStyles} $fontsize={value}>
In et felis viverra, egestas ligula nec, laoreet lacus. Nulla maximus
orci vel diam mollis consectetur. Ut sed enim finibus, sollicitudin eros
eu, venenatis metus. Nam in faucibus mi. Quisque euismod lobortis neque
ac elementum. Aenean viverra erat enim, non vehicula sapien pharetra sit
amet. Suspendisse potenti. In vitae ligula varius, efficitur dolor ut,
pulvinar libero.
</p>
</span>
);
}
Hmm not sure, let me check with the rest of the team |
Thanks for the example! I lpersonally like more the new css version btw. Another question: You don't recommend the dynamic styling because of the performance drop? the FOUC? Btw in your example there is a dynamic variable: In our case we are not able to pre-compile the css classes because each user connected to the same nextjs app has a custom theme. We can create some base classes that we know are shared, but others will require runtime computing. I was wondering if compiled is a good fit for that use case 👀, happy to hear what your team answers 😙 |
Hello! Btw the CSS version does not work dynamically with arbitrary runtime values https://stackblitz.com/edit/nextjs-olt3jd?file=src%2Fpages%2Findex.js |
Re: #1553 (comment) @dddlr Can you expand on this? Are you deprecating tagged template literals? What is the purpose of your recommendation? I have two main reasons for preferring template literals:
I understand that composition via template literals seems to have limited options in this library but am thus far willing to live with those limitations. What's going on behind the scenes? I'm guessing the docs on this topic haven't been updated since your comment. |
Yeah A few reasons for this:
Our focus over the past couple of years has been on internal adoption of and migration to Compiled in our internal Atlassian codebases, and as such we prioritise providing support for our internal developers who are trying to migrate. This may trickle down to external documentation, but it depends on whether we have the time 😅 as any support we give for external developers has always been on a best-effort basis, and ultimately dependent on whether we have time outside our normal projects. Two additional things I want to note here:
|
Hello!
In this page of the docs: https://compiledcssinjs.com/docs/limitations
You mention that there are runtime limitations, like not being able to use dynamic variables.
However this seems to work:
https://stackblitz.com/edit/nextjs-flhtjd?file=src%2Fpages%2Findex.js
It is because is an old version?
For our use case we store some style values in DB, could we use compiled to interprete the fetched values and apply them on SSR? (we are using nextjs)
Also we would need some dynamic runtimes styles like this.
The text was updated successfully, but these errors were encountered: