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: Fallback values #52

Merged
merged 19 commits into from
Apr 1, 2022

Conversation

miroslavstastny
Copy link
Member

@miroslavstastny miroslavstastny commented Feb 23, 2022

Add support for fallback values.
Fixes #27.

Any CSS property accepts an array of values which are all added to the styles.
Every browser will use the latest valid value (which might be a different one in different browsers, based on supported CSS in that browser):

import { makeStyles } from '@griffel/react';

const useClasses = makeStyles({
  root: {
    overflowY: ['scroll', 'overlay'],
  },
});

Produces following CSS:

.f1qdoogn{
  overflow-y: scroll;  /* Fallback for browsers which do not support overflow: overlay */
  overflow-y: overlay; /* Used by browsers which support overflow: overlay */
}

export type BorderStyleInput = ValueOrArray<CSS.Property.BorderStyle>;
export type BorderColorInput = ValueOrArray<CSS.Property.BorderColor>;

export type BorderRadiusInput = ValueOrArray<CSS.Property.BorderRadius<GriffelStylesCSSValue>>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

radius shorthand used just GriffelStylesCSSValue not allowing initial and similar values. Not sure there was any reason for that, I think this type is more correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same applies to margin and padding

@miroslavstastny miroslavstastny self-assigned this Mar 10, 2022
@ling1726 ling1726 changed the title feat: Fallback values 17264 Mar 17, 2022
@miroslavstastny miroslavstastny changed the title 17264 feat: Fallback values Mar 18, 2022

const useClasses = makeStyles({
root: {
overflowY: ['scroll', 'overlay'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ironically, csstype typings currently do not accept overlay as a valid value for overflow 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miroslavstastny miroslavstastny marked this pull request as ready for review March 21, 2022 12:06
@miroslavstastny miroslavstastny requested a review from a team as a code owner March 21, 2022 12:06
packages/core/src/runtime/compileCSS.test.ts Outdated Show resolved Hide resolved
packages/core/src/runtime/compileCSS.ts Outdated Show resolved Hide resolved
packages/core/src/runtime/resolveStyleRules.ts Outdated Show resolved Hide resolved
packages/core/src/runtime/resolveStyleRules.ts Outdated Show resolved Hide resolved
packages/core/src/runtime/resolveStyleRules.ts Outdated Show resolved Hide resolved
packages/core/src/runtime/resolveStyleRules.test.ts Outdated Show resolved Hide resolved
apps/website/docs/react/api/make-styles.md Show resolved Hide resolved
@miroslavstastny miroslavstastny merged commit 05635e1 into microsoft:main Apr 1, 2022
@miroslavstastny miroslavstastny deleted the feat/fallback-values branch April 1, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for fallback values
2 participants