-
Notifications
You must be signed in to change notification settings - Fork 341
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
feat: style attribute #4261
base: develop
Are you sure you want to change the base?
feat: style attribute #4261
Conversation
Is it meant to replace |
I'd like to keep current background/textColor behavior. But, what I see people struggle with is to understand what User must be able to use Component without global config. Right now, we require user to have global config registered even if only one simple component is used. It negatively affects bundle size. For example, VaButton: <VaButton /> :root {
--va-button-background: var(--va-primary);
--va-button-text-color: var(--va-on-primary);
}
.va-button {
background: var(--va-button-background);
color: var(--va-button-text-color);
} We need to find a way to handle these styles with Global Config Local CSS variablesComponent changes to <VaButton /> :root {
--va-button-background: var(--va-primary);
--va-button-text-color: var(--va-on-primary);
}
.va-button {
background: var(--va-button-background-attr, --va-button-background);
color: var( --va-button-text-color-attr, --va-button-on-background-attr, --va-button-text-color);
} This means -attr suffix has priority over default CSS variables. We can set -attr variables with global config.
Global Config knows about CSS variablesWe simply override component CSS variable. <VaButton style:background="info" style:text-color="warning" /> Transformed to: <VaButton :style="{
--va-button-background: getColor('info'),
--va-button-text-color: getColor('warning')
}" /> The problem appears when we don't have text-color attribute: <VaButton style:background="info" /> Transformed to: <VaButton :style="{
--va-button-background: getColor('info'),
--va-button-text-color: getTextColor('info')
}" /> How config can know how to set textColor? We'll need a script to handle this dependency. Similar to what we have now. const { textColor } = useBackgroundAttr('background', 'textColor') const useBackgroundAttr = (backgroundPropName: string, textColorPropName: string) => {
if (attrs[textColorPropName]) { return undefined }
return getTextColor(attrs[backgroundPropName])
} DOWNSIDES:
Rename text-color to on-[property]<VaButton /> :root {
--va-button-background: var(--va-primary);
--va-button-on-background: var(--va-on-primary);
}
.va-button {
background: var(--va-button-background);
color: var(--va-button-on-background);
} We simply override component CSS variable. <VaButton style:background="info" style:on-background="warning" /> Transformed to: <VaButton :style="{
--va-button-background: getColor('info'),
--va-button-on-background: getColor('warning')
}" /> No problem if on-background is not passed. We can handle it globally. <VaButton style:background="info" /> Transformed to: <VaButton :style="{
--va-button-background: getColor('info'),
--va-button-on-background: getTextColor('info')
}" /> When generating variables in configTransform. if (!isColor(prop)) { return makeCssVarible(prop, attrs[prop]) }
if (hasOnColorProp(prop)) {
return [
makeCssVariable('on-' + prop, getTextColor(attrs[prop]),
makeCssVarible(prop, getColor(attrs[prop]))
]
}
return makeCssVarible(prop, getColor(attrs[prop])) DOWNSIDE:
Looks like current behavior is the best. |
I'd like color prop to override Ideally, the initial idea was to have CSS variables without any prefix. We also need to decide if |
We also have <VaButton style:background="transparent" style:text-color="primary" child:loading-icon="{ 'style:color': 'success' }" /> This looks awful. But it is designed for presets, not direct usage: myWeirdPresset: {
'style:background': 'transparent',
'style:text-color': (props) => props.color,
'style:border-color': (props) => props.color,
'child:loading-icon': {
'style:color': 'success'
}
} |
RAW PROPOSAL
closes #981