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

chore: replace @fluentui/make-styles with @griffel/core #21320

Merged
Merged
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 apps/perf-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@fluentui/eslint-plugin": "*"
},
"dependencies": {
"@fluentui/make-styles": "9.0.0-beta.3",
"@griffel/core": "1.0.7",
"@fluentui/react": "^8.49.7",
"@fluentui/react-avatar": "9.0.0-beta.4",
"@fluentui/react-button": "9.0.0-beta.5",
Expand Down
2 changes: 1 addition & 1 deletion apps/perf-test/src/scenarios/MakeStyles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeClasses, makeStyles, createDOMRenderer } from '@fluentui/make-styles';
import { mergeClasses, makeStyles, createDOMRenderer } from '@griffel/core';
Copy link
Member Author

Choose a reason for hiding this comment

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

This perf test should migrate sooner or later to Griffel repo itself.

import * as React from 'react';

const renderer = createDOMRenderer(document);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "migrate to use @griffel/core",
"packageName": "@fluentui/babel-make-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "migrate to use @griffel/core",
"packageName": "@fluentui/jest-serializer-make-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "migrate to use @griffel/core",
"packageName": "@fluentui/react-make-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MakeStylesStyle } from '@fluentui/make-styles';
import { GriffelStyle } from '@griffel/core';
import { tokens } from '@fluentui/react-theme';

export const createMixin = (rule: MakeStylesStyle): MakeStylesStyle => ({
export const createMixin = (rule: GriffelStyle): GriffelStyle => ({
color: tokens.colorBrandBackground,
...rule,
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { MakeStylesStyle } from '@fluentui/make-styles';
import { GriffelStyle } from '@griffel/core';
import { tokens } from '@fluentui/react-theme';

export const flexStyles: MakeStylesStyle = {
export const flexStyles: GriffelStyle = {
display: 'flex',
flexDirection: 'column',
};

export const gridStyles = (gridGap: string): MakeStylesStyle => ({
export const gridStyles = (gridGap: string): GriffelStyle => ({
display: 'grid',
gridRowGap: gridGap,
});

export const typography: Record<'text' | 'header', MakeStylesStyle> = {
export const typography: Record<'text' | 'header', GriffelStyle> = {
text: { fontWeight: tokens.fontWeightRegular },
header: { fontWeight: 'bold' },
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MakeStylesStyle } from '@fluentui/make-styles';
import { GriffelStyle } from '@griffel/core';

export const sharedStyles: Record<string, MakeStylesStyle> = {
export const sharedStyles: Record<string, GriffelStyle> = {
root: { display: 'flex' },
container: { display: 'grid' },
};
2 changes: 1 addition & 1 deletion packages/babel-make-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@babel/preset-typescript": "^7.10.4",
"@babel/template": "^7.12.13",
"@babel/traverse": "^7.12.13",
"@fluentui/make-styles": "9.0.0-beta.3",
"@griffel/core": "1.0.7",
"@linaria/babel-preset": "^3.0.0-beta.14",
"@linaria/shaker": "^3.0.0-beta.14",
"ajv": "^8.4.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-make-styles/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NodePath, PluginObj, PluginPass, types as t } from '@babel/core';
import { declare } from '@babel/helper-plugin-utils';
import { Module } from '@linaria/babel-preset';
import shakerEvaluator from '@linaria/shaker';
import { resolveStyleRulesForSlots, CSSRulesByBucket, StyleBucketName, MakeStylesStyle } from '@fluentui/make-styles';
import { resolveStyleRulesForSlots, CSSRulesByBucket, StyleBucketName, GriffelStyle } from '@griffel/core';

import { astify } from './utils/astify';
import { evaluatePaths } from './utils/evaluatePaths';
Expand Down Expand Up @@ -159,7 +159,7 @@ export const plugin = declare<Partial<BabelPluginOptions>, PluginObj<BabelPlugin
);
}

const stylesBySlots: Record<string /* slot */, MakeStylesStyle> = evaluationResult.value;
const stylesBySlots: Record<string /* slot */, GriffelStyle> = evaluationResult.value;
const [classnamesMapping, cssRules] = resolveStyleRulesForSlots(stylesBySlots);

// TODO: find a better way to replace arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import * as React from 'react';
import { createReferenceFromClick, Box, Portal, PositioningProps, usePopper } from '@fluentui/react-northstar';
import {
ICSSInJSStyle,
createReferenceFromClick,
Box,
Portal,
PositioningProps,
usePopper,
} from '@fluentui/react-northstar';

const boxStyles: React.CSSProperties = {
const boxStyles: ICSSInJSStyle = {
Copy link
Member

Choose a reason for hiding this comment

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

why were changes to N* necssary ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changes in N*
Typings changes are related to csstype bump

image

Opened for a better solution.

border: '1px dashed #ccc',
color: 'blue',
textAlign: 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ exports[`emotionRenderer prefixes required styles 1`] = `
-webkit-filter: blur(5px);
filter: blur(5px);
height: min-content;
-webkit-position: sticky;
position: sticky;
-webkit-transition: width 2s, height 2s, background-color 2s,
-webkit-transform 2s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useTelemetry,
useUnhandledProps,
} from '@fluentui/react-bindings';
import { ICSSInJSStyle } from '@fluentui/styles';
import * as React from 'react';
import * as PropTypes from 'prop-types';
import cx from 'classnames';
Expand Down Expand Up @@ -43,15 +44,15 @@ export interface ItemLayoutProps extends UIComponentProps, ContentComponentProps
renderHeaderArea?: (props: ItemLayoutProps, classes: ComponentSlotClasses) => React.ReactNode;
renderMainArea?: (props: ItemLayoutProps, classes: ComponentSlotClasses) => React.ReactNode;
/** Styled applied to the root element of the rendered component. */
rootCSS?: React.CSSProperties;
rootCSS?: ICSSInJSStyle;
/** Styled applied to the media element of the rendered component. */
mediaCSS?: React.CSSProperties;
/** Styled applied to the header element of the rendered component. */
headerCSS?: React.CSSProperties;
headerCSS?: ICSSInJSStyle;
/** Styled applied to the header media element of the rendered component. */
headerMediaCSS?: React.CSSProperties;
/** Styled applied to the content element of the rendered component. */
contentCSS?: React.CSSProperties;
contentCSS?: ICSSInJSStyle;
/** Styled applied to the content element of the rendered component. */
contentMediaCSS?: React.CSSProperties;
/** Styled applied to the end media element of the rendered component. */
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-serializer-make-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"react-test-renderer": "^16.3.0"
},
"dependencies": {
"@fluentui/make-styles": "9.0.0-beta.3"
"@griffel/core": "1.0.7"
},
"beachball": {
"disallowedChangeTypes": [
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-serializer-make-styles/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFINITION_LOOKUP_TABLE, CSSClasses } from '@fluentui/make-styles';
import { DEFINITION_LOOKUP_TABLE, CSSClasses } from '@griffel/core';

export function print(val: unknown) {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeClasses } from '@fluentui/make-styles';
import { mergeClasses } from '@fluentui/react-make-styles';
import './index';

type MergeClassesParams = Parameters<typeof mergeClasses>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeClasses } from '@fluentui/make-styles';
import { mergeClasses } from '@fluentui/react-make-styles';
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests should use imports from react-* package as this package have only in in dependencies

Copy link
Member

Choose a reason for hiding this comment

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

don't understand, why can't these tests depend on Griffel ?

Copy link
Member

Choose a reason for hiding this comment

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

oh I see you're wrapping Griffel with react-make-styles?

Copy link
Member Author

@layershifter layershifter Jan 18, 2022

Choose a reason for hiding this comment

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

oh I see you're wrapping Griffel with react-make-styles?

Yes, as we have many packages I will replace them one by one.

don't understand, why can't these tests depend on Griffel ?

It's mistake that there was @fluentui/make-styles as it is not in dependencies:

"@fluentui/react-make-styles": "9.0.0-beta.4",

They should depend on @griffel/react, but it's not a thing yet.

import './index';

type MergeClassesParams = Parameters<typeof mergeClasses>;
Expand Down
26 changes: 13 additions & 13 deletions packages/react-make-styles/etc/react-make-styles.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

```ts

import { createDOMRenderer } from '@fluentui/make-styles';
import type { CSSClassesMapBySlot } from '@fluentui/make-styles';
import type { CSSRulesByBucket } from '@fluentui/make-styles';
import type { MakeStaticStyles } from '@fluentui/make-styles';
import type { MakeStylesRenderer } from '@fluentui/make-styles';
import { MakeStylesStyle } from '@fluentui/make-styles';
import { mergeClasses } from '@fluentui/make-styles';
import { createDOMRenderer } from '@griffel/core';
import type { CSSClassesMapBySlot } from '@griffel/core';
import type { CSSRulesByBucket } from '@griffel/core';
import type { GriffelRenderer } from '@griffel/core';
import type { GriffelStaticStyles } from '@griffel/core';
import { GriffelStyle as MakeStylesStyle } from '@griffel/core';
import { mergeClasses } from '@griffel/core';
import * as React_2 from 'react';
import { shorthands } from '@fluentui/make-styles';
import { shorthands } from '@griffel/core';

// @internal
export function __styles<Slots extends string>(classesMapBySlot: CSSClassesMapBySlot<Slots>, cssRules: CSSRulesByBucket): () => Record<Slots, string>;

export { createDOMRenderer }

// @public (undocumented)
export function makeStaticStyles<Selectors>(styles: MakeStaticStyles | MakeStaticStyles[]): () => void;
export function makeStaticStyles<Selectors>(styles: GriffelStaticStyles | GriffelStaticStyles[]): () => void;

// @public (undocumented)
export function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, MakeStylesStyle>): () => Record<Slots, string>;
Expand All @@ -30,24 +30,24 @@ export { MakeStylesStyle }
export { mergeClasses }

// @public (undocumented)
export const RendererContext: React_2.Context<MakeStylesRenderer>;
export const RendererContext: React_2.Context<GriffelRenderer>;

// @public (undocumented)
export const RendererProvider: React_2.FC<RendererProviderProps>;

// @public (undocumented)
export interface RendererProviderProps {
renderer: MakeStylesRenderer;
renderer: GriffelRenderer;
targetDocument?: Document;
}

// @public
export function renderToStyleElements(renderer: MakeStylesRenderer): React_2.ReactElement[];
export function renderToStyleElements(renderer: GriffelRenderer): React_2.ReactElement[];

export { shorthands }

// @public
export function useRenderer(): MakeStylesRenderer;
export function useRenderer(): GriffelRenderer;

// (No @packageDocumentation comment for this package)

Expand Down
2 changes: 1 addition & 1 deletion packages/react-make-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@fluentui/react-shared-contexts": "9.0.0-beta.4",
"@fluentui/make-styles": "9.0.0-beta.3",
"@griffel/core": "1.0.7",
"@fluentui/react-theme": "9.0.0-beta.4",
"@fluentui/react-utilities": "9.0.0-beta.4",
"tslib": "^2.1.0"
Expand Down
10 changes: 5 additions & 5 deletions packages/react-make-styles/src/RendererContext.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createDOMRenderer, rehydrateRendererCache } from '@fluentui/make-styles';
import { createDOMRenderer, rehydrateRendererCache } from '@griffel/core';
import { canUseDOM } from '@fluentui/react-utilities';
import * as React from 'react';
import type { MakeStylesRenderer } from '@fluentui/make-styles';
import type { GriffelRenderer } from '@griffel/core';

export interface RendererProviderProps {
/** An instance of makeStyles() renderer. */
renderer: MakeStylesRenderer;
renderer: GriffelRenderer;

/**
* Document used to insert CSS variables to head
Expand All @@ -16,7 +16,7 @@ export interface RendererProviderProps {
/**
* @private
*/
export const RendererContext = React.createContext<MakeStylesRenderer>(createDOMRenderer());
export const RendererContext = React.createContext<GriffelRenderer>(createDOMRenderer());

/**
* @public
Expand All @@ -41,6 +41,6 @@ export const RendererProvider: React.FC<RendererProviderProps> = ({ children, re
*
* @private
*/
export function useRenderer(): MakeStylesRenderer {
export function useRenderer(): GriffelRenderer {
return React.useContext(RendererContext);
}
4 changes: 2 additions & 2 deletions packages/react-make-styles/src/__styles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { __styles as vanillaStyles } from '@fluentui/make-styles';
import { __styles as vanillaStyles } from '@griffel/core';
import { useFluent } from '@fluentui/react-shared-contexts';

import { useRenderer } from './RendererContext';
import type { CSSClassesMapBySlot, CSSRulesByBucket } from '@fluentui/make-styles';
import type { CSSClassesMapBySlot, CSSRulesByBucket } from '@griffel/core';

/**
* A version of makeStyles() that accepts build output as an input and skips all runtime transforms.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDOMRenderer } from '@fluentui/make-styles';
import { createDOMRenderer } from '@griffel/core';
import * as React from 'react';
import { hydrate } from 'react-dom';
import { renderToStaticMarkup } from 'react-dom/server';
Expand Down
4 changes: 2 additions & 2 deletions packages/react-make-styles/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { shorthands, mergeClasses, createDOMRenderer } from '@fluentui/make-styles';
export type { MakeStylesStyle } from '@fluentui/make-styles';
export { shorthands, mergeClasses, createDOMRenderer } from '@griffel/core';
export type { GriffelStyle as MakeStylesStyle } from '@griffel/core';

export { makeStyles } from './makeStyles';
export { makeStaticStyles } from './makeStaticStyles';
Expand Down
6 changes: 3 additions & 3 deletions packages/react-make-styles/src/makeStaticStyles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { makeStaticStyles as vanillaMakeStaticStyles } from '@fluentui/make-styles';
import { makeStaticStyles as vanillaMakeStaticStyles } from '@griffel/core';

import { useRenderer } from './RendererContext';
import type { MakeStaticStyles, MakeStaticStylesOptions } from '@fluentui/make-styles';
import type { GriffelStaticStyles, MakeStaticStylesOptions } from '@griffel/core';

export function makeStaticStyles<Selectors>(styles: MakeStaticStyles | MakeStaticStyles[]) {
export function makeStaticStyles<Selectors>(styles: GriffelStaticStyles | GriffelStaticStyles[]) {
const getStyles = vanillaMakeStaticStyles(styles);

if (process.env.NODE_ENV === 'test') {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-make-styles/src/makeStyles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { makeStyles as vanillaMakeStyles } from '@fluentui/make-styles';
import { makeStyles as vanillaMakeStyles } from '@griffel/core';
import { useFluent } from '@fluentui/react-shared-contexts';
import * as React from 'react';

import { useRenderer } from './RendererContext';
import type { MakeStylesOptions, MakeStylesStyle } from '@fluentui/make-styles';
import type { MakeStylesOptions, GriffelStyle } from '@griffel/core';

function isInsideComponent() {
try {
Expand All @@ -15,7 +15,7 @@ function isInsideComponent() {
}
}

export function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, MakeStylesStyle>) {
export function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>) {
const getStyles = vanillaMakeStyles(stylesBySlots);

if (process.env.NODE_ENV !== 'production') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// 👆 this is intentionally to test in SSR like environment

import { createDOMRenderer } from '@fluentui/make-styles';
import { createDOMRenderer } from '@griffel/core';
import * as prettier from 'prettier';
import * as React from 'react';
import * as ReactDOM from 'react-dom/server';
Expand Down
6 changes: 3 additions & 3 deletions packages/react-make-styles/src/renderToStyleElements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styleBucketOrdering } from '@fluentui/make-styles';
import { styleBucketOrdering } from '@griffel/core';
import * as React from 'react';
import type { MakeStylesRenderer, StyleBucketName } from '@fluentui/make-styles';
import type { GriffelRenderer, StyleBucketName } from '@griffel/core';

type CSSRulesGroupedByStyleBucket = Record<StyleBucketName, string[]>;

Expand All @@ -9,7 +9,7 @@ type CSSRulesGroupedByStyleBucket = Record<StyleBucketName, string[]>;
*
* @public
*/
export function renderToStyleElements(renderer: MakeStylesRenderer): React.ReactElement[] {
export function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {
const styles = styleBucketOrdering.reduce<CSSRulesGroupedByStyleBucket>((acc, bucketName) => {
return { ...acc, [bucketName]: [] };
}, {} as CSSRulesGroupedByStyleBucket);
Expand Down
Loading