-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
RFC: how to handle tokens for existing CSS-in-JS approach in v0 #12913
Conversation
Perf AnalysisNo significant results to display. All results
Perf Analysis (Fluent)Potential regressions comparing to master
Perf comparison
Perf tests with no regressions
|
IMO the 2nd option seems more organised and natural to think, I would guess also easy to maintain since the parts are well separated slot by slot? |
My vote is for option 1 as it's closer to CSS variables. Option 2 existed at some point (microsoft/fluent-ui-react#207 ??) and we removed it, however we still have some nested variables for colors 😭 Q1: How to pass variables down?I see two options: via React Context or via props (breaks caching)? Q2: Theme definition?Currently we have export { default } from './attachmentVariables'; Q3: Enforcing naming rulesIt looks that all will fit pattern Q4: Collection componentsCan you please add an example for collection components? How names will look there? |
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: 31404935a5e8287ea7e5fdb491c1deb96338b710 (build) |
I also intuitively went with option 1 in my prototyping. |
packages/fluentui/react-northstar/src/components/Attachment/Attachment.tsx
Outdated
Show resolved
Hide resolved
packages/fluentui/react-northstar/src/components/Attachment/AttachmentAction.tsx
Show resolved
Hide resolved
packages/fluentui/react-northstar/src/components/Attachment/AttachmentAction.tsx
Show resolved
Hide resolved
packages/fluentui/react-northstar/src/components/Attachment/Attachment.tsx
Outdated
Show resolved
Hide resolved
|
||
AttachmentBody.propTypes = commonPropTypes.createCommon(); | ||
|
||
AttachmentBody.create = createShorthandFactory({ Component: AttachmentBody, mappedProp: 'content' }); | ||
AttachmentBody.shorthandConfig = { |
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.
Technically this is a breaking change, but as this was never released we are good
@@ -140,12 +140,16 @@ const Attachment = compose<'div', AttachmentProps, AttachmentStylesProps, {}, {} | |||
_.invoke(props, 'onClick', e, props); | |||
}; | |||
|
|||
const mergeShorthandVariables = (variables, shorthandVariables) => { | |||
return (variables || shorthandVariables) && mergeComponentVariables(variables, shorthandVariables); | |||
}; |
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.
At least let's move this out of render scope and add a comment to do something with as obviously this about is not a key to the bright future
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.
Moved and added comment. I agree that we should wither fix mergeComponentVariables or provide similar utility
-updated changelog
BREAKING CHANGE
Removed the following properties from the
AttachmentAction
component:If any of these is needed we can add it after it is requested
Tokens structure
Problem description
Variables (tokens) are a way of customizing styles in the Fluent components. For example:
will update the attachment to have blue background.
For customizing the root component itself we don't have any problems, but for the slots things are starting to get more interesting.
Let's see the next example
We would expect that the following will happen:
But that's not true unfortunately :(
However this code, will produce the prev look:
Let's see why this is happening
The
AttachmentAction
which is used for the action slot, is composing theButton
component. TheButton
component has it's own styles and variables. If we just use theAttachment
's variables for theAttachmentAction
, we will have a problem, because we will have variables name collision - both theButton
and theAttachment
havebackgroundColor
variable, that's why the last code snippet updated the background color for the action.How can we solve this?
Proposed solution
When composing components for our Fluent slots, we should always override the styles for the base component. That means that we will always need to write the styles from scratch, but it will allow us to use the parent's components variables and pick the correct variables which are intended for the slot (for example set the background color to be the
actionBackgroundColor
variable in theAttachmentAction
's styles). This will also save us from unpredictable regressions, when we are updating the styles for one component, but that is doing changes all over the codebases, where the styles of this component may have been used/composed.In addition to this, it will mean that we won't need to have variables for the slots components. This will be possible because all variables for a component will be defined on the root level, where we can structure the variables names to always start with the slot name, or we can have object structure for the slots.
Option 1
Option 2
Apart from this, we have to share the variables between the parent and children components via context, so that the variables usage in the parent component can trigger updates in the styles of the children components inside.
I am leaning towards #Option1.1 as it is closed to what we have, plus it will preserve the flat variables structure, which is closed to the CSS variables