Skip to content

Commit

Permalink
Rename makeStyles to makeStyleCompat (microsoft#17354)
Browse files Browse the repository at this point in the history
* Change makeStyle to makeStyleCompat

* Change files

* Fix change file typo

* Updates makeStyles file name to makeStylesCompat
  • Loading branch information
bsunderhus authored and joshualamusga1 committed Mar 25, 2021
1 parent 1624dbb commit 46f37c0
Show file tree
Hide file tree
Showing 41 changed files with 169 additions and 88 deletions.
6 changes: 3 additions & 3 deletions apps/perf-test/src/scenarios/MakeStyles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from 'react';
import { ax, makeStyles, createDOMRenderer } from '@fluentui/make-styles';
import { ax, makeStylesCompat, createDOMRenderer } from '@fluentui/make-styles';

const renderer = createDOMRenderer();

Expand Down Expand Up @@ -66,7 +66,7 @@ const staticViewStyles: any = [
],
];

const useStaticViewStyles = makeStyles(staticViewStyles);
const useStaticViewStyles = makeStylesCompat(staticViewStyles);
const View: React.FunctionComponent<{ className?: string }> = props => {
const { className } = props;
const classes = ax(useStaticViewStyles({}, { renderer, tokens: {} }), className);
Expand Down Expand Up @@ -121,7 +121,7 @@ const staticBoxStyles: any = [
],
];

const useStaticBoxStyles = makeStyles(staticBoxStyles);
const useStaticBoxStyles = makeStylesCompat(staticBoxStyles);

const Box: React.FunctionComponent<{}> = () => {
const classes = useStaticBoxStyles(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/make-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-avatar",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-badge",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-button",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-cards",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-examples",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-image",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-link",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-make-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-menu",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Change makeStyles to makeStylesCompat",
"packageName": "@fluentui/react-text",
"email": "[email protected]",
"dependentChangeType": "patch"
}
40 changes: 22 additions & 18 deletions packages/make-styles/src/ax.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ax } from './ax';
import { makeStyles } from './makeStyles';
import { makeStylesCompat } from './makeStylesCompat';
import { createDOMRenderer } from './renderer/createDOMRenderer';
import { MakeStylesOptions } from './types';

Expand All @@ -20,25 +20,29 @@ describe('ax', () => {
});

it('performs deduplication for multiple arguments', () => {
const className1 = makeStyles([[null, { display: 'block' }]])({}, options);
const className2 = makeStyles([[null, { display: 'flex' }]])({}, options);
const className3 = makeStyles([[null, { display: 'grid' }]])({}, options);
const className4 = makeStyles([[null, { padding: '5px' }]])({}, options);
const className1 = makeStylesCompat([[null, { display: 'block' }]])({}, options);
const className2 = makeStylesCompat([[null, { display: 'flex' }]])({}, options);
const className3 = makeStylesCompat([[null, { display: 'grid' }]])({}, options);
const className4 = makeStylesCompat([[null, { padding: '5px' }]])({}, options);

const resultClassName = makeStyles([[null, { display: 'grid', padding: '5px' }]])({}, options);
const resultClassName = makeStylesCompat([[null, { display: 'grid', padding: '5px' }]])({}, options);

expect(ax(className1, className2, className3, className4)).toBe(resultClassName);
});

it('order of classes is not important', () => {
const className = makeStyles([[null, { display: 'block' }]])({}, options);
const className = makeStylesCompat([[null, { display: 'block' }]])({}, options);

expect(ax('ui-button', className, 'ui-button-content')).toBe(`ui-button ui-button-content ${className}`);
});

it('order of classes is not important for multilevel overrides', () => {
const className1 = ax('ui-button', makeStyles([[null, { display: 'block' }]])({}, options), 'ui-button-content');
const className2 = makeStyles([[null, { display: 'grid' }]])({}, options);
const className1 = ax(
'ui-button',
makeStylesCompat([[null, { display: 'block' }]])({}, options),
'ui-button-content',
);
const className2 = makeStylesCompat([[null, { display: 'grid' }]])({}, options);

expect(ax(className1, className2)).toBe(`ui-button ui-button-content ${className2}`);
});
Expand All @@ -53,14 +57,14 @@ describe('ax', () => {
// });

it('merges multi-level overrides properly', () => {
const className1 = makeStyles([[null, { display: 'block' }]])({}, options);
const className2 = makeStyles([[null, { display: 'flex' }]])({}, options);
const className1 = makeStylesCompat([[null, { display: 'block' }]])({}, options);
const className2 = makeStylesCompat([[null, { display: 'flex' }]])({}, options);

const sequence1 = ax('ui-button', className1, className2);

const className3 = makeStyles([[null, { display: 'grid' }]])({}, options);
const className4 = makeStyles([[null, { padding: '5px' }]])({}, options);
const className5 = makeStyles([[null, { marginTop: '5px' }]])({}, options);
const className3 = makeStylesCompat([[null, { display: 'grid' }]])({}, options);
const className4 = makeStylesCompat([[null, { padding: '5px' }]])({}, options);
const className5 = makeStylesCompat([[null, { marginTop: '5px' }]])({}, options);

const sequence2 = ax('ui-flex', className3, className4);
const sequence3 = ax(sequence1, sequence2, className5);
Expand All @@ -74,8 +78,8 @@ describe('ax', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const error = jest.spyOn(console, 'error').mockImplementationOnce(() => {});

const className1 = makeStyles([[null, { display: 'block' }]])({}, options);
const className2 = makeStyles([[null, { display: 'flex' }]])({}, options);
const className1 = makeStylesCompat([[null, { display: 'block' }]])({}, options);
const className2 = makeStylesCompat([[null, { display: 'flex' }]])({}, options);

ax(className1 + ' ' + className2);

Expand All @@ -87,8 +91,8 @@ describe('ax', () => {
describe('unstable functionality', () => {
it('deduplicates classes with mixed priority', () => {
// Classnames with numeric suffix has increased specificity
const className1 = makeStyles([[null, { display: 'grid' }]])({}, options);
const className2 = makeStyles([[null, { display: 'flex' }]], 1)({}, options);
const className1 = makeStylesCompat([[null, { display: 'grid' }]])({}, options);
const className2 = makeStylesCompat([[null, { display: 'flex' }]], 1)({}, options);

expect(ax(className1, className2)).toBe(className2);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/make-styles/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { createDOMRenderer } from './renderer/createDOMRenderer';

export { ax } from './ax';
export { makeStyles } from './makeStyles';
export { makeStylesCompat } from './makeStylesCompat';
export { makeStaticStyles } from './makeStaticStyles';

export * from './types';
4 changes: 2 additions & 2 deletions packages/make-styles/src/makeStaticStyles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getCSSRules } from '@fluentui/test-utilities';
import { createDOMRenderer, MakeStylesDOMRenderer, resetDOMRenderer } from './renderer/createDOMRenderer';
import { makeStaticStyles } from './makeStaticStyles';
import { cssRulesSerializer, makeStylesRulesSerializer } from './utils/test/snapshotSerializer';
import { makeStyles } from './makeStyles';
import { makeStylesCompat } from './makeStylesCompat';

expect.addSnapshotSerializer(cssRulesSerializer);
expect.addSnapshotSerializer(makeStylesRulesSerializer);
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('makeStaticStyles', () => {
},
});

const useStyles = makeStyles([
const useStyles = makeStylesCompat([
[
null,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCSSRules } from '@fluentui/test-utilities';
import { createDOMRenderer, MakeStylesDOMRenderer, resetDOMRenderer } from './renderer/createDOMRenderer';
import { makeStyles } from './makeStyles';
import { makeStylesCompat } from './makeStylesCompat';
import { cssRulesSerializer } from './utils/test/snapshotSerializer';

/* eslint-disable @fluentui/max-len */
Expand All @@ -18,7 +18,7 @@ describe('makeStyles', () => {
});

it('returns a single classname for a single style', () => {
const computeClasses = makeStyles([[null, { color: 'red' }]]);
const computeClasses = makeStylesCompat([[null, { color: 'red' }]]);
expect(computeClasses({}, { renderer, tokens: {} })).toBe('__ncdyee0 fe3e8s90');

expect(getCSSRules(renderer.styleElement)).toMatchInlineSnapshot(`
Expand All @@ -29,7 +29,7 @@ describe('makeStyles', () => {
});

it('returns multiple classnames for complex rules', () => {
const computeClasses = makeStyles([[null, { color: 'red', position: 'absolute' }]]);
const computeClasses = makeStylesCompat([[null, { color: 'red', position: 'absolute' }]]);
expect(computeClasses({}, { renderer, tokens: {} })).toBe('__1fslksb fe3e8s90 f1euv43f');

expect(getCSSRules(renderer.styleElement)).toMatchInlineSnapshot(`
Expand All @@ -43,7 +43,7 @@ describe('makeStyles', () => {
});

it('handles RTL for keyframes', () => {
const computeClasses = makeStyles([
const computeClasses = makeStylesCompat([
[
null,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MakeStylesResolvedDefinition,
} from './types';

export function makeStyles<Selectors, Tokens>(
export function makeStylesCompat<Selectors, Tokens>(
definitions: MakeStylesDefinition<Selectors, Tokens>[],
unstable_cssPriority: number = 0,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ax, makeStyles } from '@fluentui/react-make-styles';
import { ax, makeStylesCompat } from '@fluentui/react-make-styles';
import { getNativeProps, htmlElementProperties } from '@fluentui/react-utilities';
import * as React from 'react';

const useRootStyles = makeStyles([
const useRootStyles = makeStylesCompat([
[
null,
{
Expand All @@ -15,7 +15,7 @@ const useRootStyles = makeStyles([
],
]);

const useSvgStyles = makeStyles([
const useSvgStyles = makeStylesCompat([
[
null,
{
Expand Down
10 changes: 5 additions & 5 deletions packages/react-avatar/src/components/Avatar/useAvatarStyles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ax, makeStyles } from '@fluentui/react-make-styles';
import { ax, makeStylesCompat } from '@fluentui/react-make-styles';
import { GlobalSharedColors, Theme } from '@fluentui/react-theme';
import { AvatarState } from './Avatar.types';

Expand Down Expand Up @@ -77,7 +77,7 @@ const avatarColor = (theme: Theme, name: keyof GlobalSharedColors) => ({
background: theme.alias.color[name].background2,
});

const useStyles = makeStyles<AvatarState>([
const useStyles = makeStylesCompat<AvatarState>([
[
null,
theme => ({
Expand Down Expand Up @@ -239,7 +239,7 @@ const useStyles = makeStyles<AvatarState>([
],
]);

const useBadgeStyles = makeStyles<AvatarState>([
const useBadgeStyles = makeStylesCompat<AvatarState>([
[
null,
{
Expand All @@ -265,7 +265,7 @@ const useBadgeStyles = makeStyles<AvatarState>([
[s => s.size >= 128, { '--badge-size': '32px' }],
]);

const useImageStyles = makeStyles<AvatarState>([
const useImageStyles = makeStylesCompat<AvatarState>([
[
null,
{
Expand All @@ -282,7 +282,7 @@ const useImageStyles = makeStyles<AvatarState>([
],
]);

const useLabelStyles = makeStyles<AvatarState>([
const useLabelStyles = makeStylesCompat<AvatarState>([
[
null,
theme => ({
Expand Down
6 changes: 3 additions & 3 deletions packages/react-avatar/src/components/Badge/useBadgeStyles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ax, makeStyles } from '@fluentui/react-make-styles';
import { ax, makeStylesCompat } from '@fluentui/react-make-styles';
import { BadgeState } from './Badge.types';

const useRootStyles = makeStyles<BadgeState>([
const useRootStyles = makeStylesCompat<BadgeState>([
[
null,
{
Expand Down Expand Up @@ -121,7 +121,7 @@ const useRootStyles = makeStyles<BadgeState>([
],
]);

const useIconStyles = makeStyles([
const useIconStyles = makeStylesCompat([
[
null,
{
Expand Down
6 changes: 3 additions & 3 deletions packages/react-badge/src/components/Badge/useBadgeStyles.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { makeStyles, ax } from '@fluentui/react-make-styles';
import { makeStylesCompat, ax } from '@fluentui/react-make-styles';
import { BadgeState } from './Badge.types';

/**
* Styles for the root slot
*/
export const useRootStyles = makeStyles<BadgeState>([
export const useRootStyles = makeStylesCompat<BadgeState>([
[
null,
theme => ({
Expand Down Expand Up @@ -117,7 +117,7 @@ export const useRootStyles = makeStyles<BadgeState>([
/**
* Styles for the icon slot
*/
export const useIconStyles = makeStyles<BadgeState>([
export const useIconStyles = makeStylesCompat<BadgeState>([
[
s => !s.children,
() => ({
Expand Down
Loading

0 comments on commit 46f37c0

Please sign in to comment.