Skip to content
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: Allow "var(--" strings as values for all properties #650

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rollup-plugin/flow_modules/rollup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ export type SequentialPluginHooks =
| 'transform';

export type ParallelPluginHooks = Exclude<
$Keys<FunctionPluginHooks> | $Keys<AddonHooks>,
$Keys<FunctionPluginHooks> | AddonHooks,
FirstPluginHooks | SequentialPluginHooks,
>;

Expand Down
10 changes: 6 additions & 4 deletions packages/shared/src/physical-rtl/generate-ltr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* @flow strict
*/

const logicalToPhysical: $ReadOnly<{ [string]: string }> = {
const logicalToPhysical: $ReadOnly<{ [string]: ?string }> = {
start: 'left',
end: 'right',
};

const propertyToLTR: $ReadOnly<{
[key: string]: ($ReadOnly<[string, string]>) => $ReadOnly<[string, string]>,
[key: string]: ?($ReadOnly<[string, string]>) => $ReadOnly<[string, string]>,
}> = {
'margin-start': ([_key, val]: $ReadOnly<[string, string]>) => [
'margin-left',
Expand Down Expand Up @@ -122,8 +122,10 @@ export default function generateLTR(
pair: $ReadOnly<[string, string]>,
): $ReadOnly<[string, string]> {
const [key] = pair;
if (propertyToLTR[key]) {
return propertyToLTR[key](pair);

const property = propertyToLTR[key];
if (property) {
return property(pair);
}
return pair;
}
9 changes: 5 additions & 4 deletions packages/shared/src/physical-rtl/generate-rtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import parser from 'postcss-value-parser';

const cursorFlip: $ReadOnly<{ [string]: string }> = {
const cursorFlip: $ReadOnly<{ [string]: ?string }> = {
'e-resize': 'w-resize',
'w-resize': 'e-resize',
'ne-resize': 'nw-resize',
Expand Down Expand Up @@ -98,7 +98,7 @@ const logicalToPhysical: $ReadOnly<{ [string]: ?string }> = {
};

const propertyToRTL: $ReadOnly<{
[key: string]: (
[key: string]: ?(
$ReadOnly<[string, string]>,
) => $ReadOnly<[string, string]> | null,
}> = {
Expand Down Expand Up @@ -181,8 +181,9 @@ const propertyToRTL: $ReadOnly<{
export default function generateRTL([key, value]: $ReadOnly<
[string, string],
>): ?$ReadOnly<[string, string]> {
if (propertyToRTL[key]) {
return propertyToRTL[key]([key, value]);
const toRTLForKey = propertyToRTL[key];
if (toRTLForKey) {
return toRTLForKey([key, value]);
}
return null;
}
3 changes: 1 addition & 2 deletions packages/shared/src/preprocess-rules/basic-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function validateConditionalStyles(
val: ConditionalStyles,
conditions: $ReadOnlyArray<string> = [],
): void {
for (const key in val) {
const v = val[key];
for (const [key, v] of Object.entries(val)) {
if (!(key.startsWith('@') || key.startsWith(':') || key === 'default')) {
throw new Error(messages.INVALID_PSEUDO_OR_AT_RULE);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/transform-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const unitlessNumberProperties = new Set([
]);

// List of properties that have custom suffixes for numbers
const numberPropertySuffixes: { +[key: string]: string } = {
const numberPropertySuffixes: { +[key: string]: ?string } = {
animationDelay: 'ms',
animationDuration: 'ms',
transitionDelay: 'ms',
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/utils/property-priorities.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ longHandLogical.add('touch-action');
// ':active': 170,
// };

export const PSEUDO_CLASS_PRIORITIES: $ReadOnly<{ [string]: number }> = {
export const PSEUDO_CLASS_PRIORITIES: $ReadOnly<{ [string]: ?number }> = {
':is': 40,
':where': 40,
':not': 40,
Expand Down
2 changes: 1 addition & 1 deletion packages/stylex/src/StyleXCSSTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type alignSelf =
| 'safe center'
| 'unsafe center'
| all;
type all = null | 'initial' | 'inherit' | 'unset';
type all = null | 'initial' | 'inherit' | 'unset' | StringPrefix<'var(--'>;
type animationDelay = time;
type animationDirection = singleAnimationDirection;
type animationDuration = time;
Expand Down