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

Update react-button for preview release #17060

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a1e550f
scaffold stories from figma
levithomason Feb 8, 2021
ad3f46d
begin adding react-button converged tokens
levithomason Feb 8, 2021
a1e3060
add more button tokens to makestyles call
levithomason Feb 9, 2021
99e9bd9
merge master
levithomason Feb 9, 2021
62c34ac
continue adding variants and their tokens
levithomason Feb 11, 2021
027bf7b
continue adding variants and their tokens
levithomason Feb 11, 2021
bb7d6cc
fix icon spacing update button token dump
levithomason Feb 11, 2021
db35d53
rework component token table
levithomason Feb 12, 2021
8f493bc
more button tokens
levithomason Feb 12, 2021
e10faa7
merge master, use makeStaticStyles
levithomason Feb 16, 2021
34178f7
fix statics and tokens
levithomason Feb 16, 2021
ebd0839
add more todo for static styles, need to wire hook
levithomason Feb 16, 2021
34d4e16
used tokens storybook addon
miroslavstastny Feb 17, 2021
a808420
start resolving token panel values
levithomason Feb 17, 2021
a6a12e6
FluentTokens addon: debug theme encapsulated
miroslavstastny Feb 18, 2021
7613fea
initial cleanup for button prerelease and storybook
levithomason Feb 18, 2021
8818220
initial cleanup for button prerelease and storybook
levithomason Feb 18, 2021
00c122b
clean up cruft
levithomason Feb 19, 2021
df335f6
more cleanup
levithomason Feb 19, 2021
b49dd1c
you guessed it, more clean up
levithomason Feb 19, 2021
8bab9f3
...
levithomason Feb 19, 2021
ec76154
...
levithomason Feb 19, 2021
2e43a45
delete bunch of stuff
levithomason Feb 19, 2021
ca0bd1b
delete bunch of stuff
levithomason Feb 19, 2021
35bae47
add todo
levithomason Feb 19, 2021
6fc1722
remove data-is-focusable
levithomason Feb 22, 2021
7e782f8
merge master, fix issues
levithomason Feb 22, 2021
3637751
stub disabled tokens, fix issues
levithomason Feb 22, 2021
514bf73
Disabled styles
miroslavstastny Feb 22, 2021
a1d10d6
move todos to proper line
levithomason Feb 22, 2021
cb37d4e
merge master, again, fix conflicts
levithomason Feb 22, 2021
e4c2eb0
comment out unsupported props
levithomason Feb 22, 2021
3f815a8
clean up todos
levithomason Feb 22, 2021
69597b0
revert react-provider changes
levithomason Feb 22, 2021
53b52e8
remove todo
levithomason Feb 22, 2021
fbad0d9
remove static styles
levithomason Feb 22, 2021
86e1994
fix typings
levithomason Feb 22, 2021
8847843
make react-button build
levithomason Feb 23, 2021
182a165
merge master
levithomason Feb 23, 2021
cdc8e3d
fix tests
levithomason Feb 23, 2021
ffb6d45
restore web components from master
levithomason Feb 23, 2021
ec87823
restore react-utilities from master
levithomason Feb 23, 2021
8907084
fix props typing, sync tsconfig with react-link
levithomason Feb 23, 2021
fdbc88c
miro fixes levi
levithomason Feb 23, 2021
a4650ca
api changes
levithomason Feb 23, 2021
bb23a02
Change files
levithomason Feb 23, 2021
bc9c7af
merge master
levithomason Feb 24, 2021
63ab023
remove duplicate packages in storybook preview.js
levithomason Feb 24, 2021
e16fa3c
remove unused style matchers
levithomason Feb 24, 2021
b810c40
fix button props, add vr-tests
levithomason Feb 25, 2021
37a58d4
fix vr-test typings
levithomason Feb 25, 2021
7d5d81a
merge master
levithomason Feb 25, 2021
ce1c139
merge master, fix conflicts
levithomason Feb 25, 2021
373e33b
fix icon package name merge issue
levithomason Feb 25, 2021
7d26248
rename useButtonClasses to useButtonStyles
levithomason Feb 25, 2021
e01e900
remove unused css variables
levithomason Feb 25, 2021
b95fcfa
add todo for gap and fix remaining useClasses names
levithomason Feb 25, 2021
bb7d85b
Merge branch 'master' of https://github.com/microsoft/fluentui into f…
layershifter Feb 25, 2021
1f7901d
fix versions
layershifter Feb 25, 2021
dbf403b
fix API
layershifter Feb 25, 2021
6de7d16
fix typings
layershifter Feb 25, 2021
5ef0ab3
delete stories for compat Provider
layershifter Feb 25, 2021
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
49 changes: 49 additions & 0 deletions packages/make-styles/src/makeStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ import {
MakeStylesResolvedDefinition,
} from './types';

class UsedVariables {
public tokens: Record<string, boolean> = {};
public addUsed(vars: string[]) {
vars.forEach(v => {
this.tokens[v] = true;
});
}
public addOther(vars: string[]) {
vars.forEach(v => {
this.tokens[v] = this.tokens[v] ?? false;
});
}
}

export function makeStyles<Selectors, Tokens>(
definitions: MakeStylesDefinition<Selectors, Tokens>[],
unstable_cssPriority: number = 0,
Expand All @@ -29,6 +43,9 @@ export function makeStyles<Selectors, Tokens>(
// unstable_cssPriority,
// );
// } else {
const { debug } = options;
// DEBUG // console.groupCollapsed(`computeClasses[${debug?.debugId}]`);

const tokens = CAN_USE_CSS_VARIABLES ? createCSSVariablesProxy(options.tokens) : options.tokens;
const resolvedDefinitions = resolveDefinitions(
(definitions as unknown) as MakeStylesResolvedDefinition<Selectors, Tokens>[],
Expand All @@ -40,14 +57,46 @@ export function makeStyles<Selectors, Tokens>(
let matchedIndexes = '';
const matchedDefinitions: MakeStylesMatchedDefinitions[] = [];

const usedVariables = new UsedVariables();

for (let i = 0, l = resolvedDefinitions.length; i < l; i++) {
const matcherFn = resolvedDefinitions[i][0];

const referencedVars: string[] = [];
Object.keys(resolvedDefinitions[i][2])
.map(key => resolvedDefinitions[i][2][key][1])
.reduce((sum, style) => {
const regexp = RegExp('\\Wvar\\s*\\(\\s*(--[\\w-]+)', 'g');
let match;
while ((match = regexp.exec(style)) !== null) {
sum.add(match[1]);
}
return sum;
}, new Set())
.forEach(cssVar => referencedVars.push(cssVar));

if (matcherFn === null || matcherFn(selectors)) {
// DEBUG // console.group(`%c HIT - ${debug?.debugId} matcher:`, 'color: green', matcherFn, {
// DEBUG // definition: resolvedDefinitions[i][2],
// DEBUG // });
usedVariables.addUsed(referencedVars);

matchedDefinitions.push(resolvedDefinitions[i][2]);
matchedIndexes += i;
} else {
// DEBUG // console.group(`%c MISS ${debug?.debugId} matcher:`, 'color: red', matcherFn, {
// DEBUG // definition: resolvedDefinitions[i][2],
// DEBUG // });
usedVariables.addOther(referencedVars);
}
// DEBUG // console.log(referencedVars);
// DEBUG // console.groupEnd();
}

if (debug?.tokens) {
debug.tokens = usedVariables.tokens;
}
// DEBUG // console.groupEnd();

const cxCacheKey = options.renderer.id + matchedIndexes;
const cxCacheElement = cxCache[cxCacheKey];
Expand Down
12 changes: 10 additions & 2 deletions packages/make-styles/src/renderer/createDOMRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ export function createDOMRenderer(targetDocument: Document = document): MakeStyl

renderer.insertionCache[cacheKey] = true;

(renderer.styleElement.sheet as CSSStyleSheet).insertRule(ruleCSS, renderer.index);
renderer.index++;
// The browser will fail to insert rule syntax it doesn't understand, such as :-moz-focusring selectors
// We want to log the error but continue with other rules instead of aborting
// See also: https://github.com/vercel/styled-jsx/issues/295
try {
(renderer.styleElement.sheet as CSSStyleSheet).insertRule(ruleCSS, renderer.index);
renderer.index++;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
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 PR is also adding static styles for normalize.css, box-sizing, and font faces. This change is required to allow those to render.

Copy link
Member

Choose a reason for hiding this comment

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

This change was revert in 69597b0, correct?

}

return classes.slice(0, -1);
Expand Down
2 changes: 2 additions & 0 deletions packages/make-styles/src/runtime/resolveDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ export function resolveDefinitions<Selectors, Tokens>(
// we can always use prebuilt styles in this case and static cache in runtime

if (resolvedRule) {
// DEBUG // console.log(`resolveDefinitions[${i}] - already resolved`);
return [matcher, undefined, resolvedRule];
}

// DEBUG // console.log(`resolveDefinitions[${i}] - resolving`);
// if static cache is not present, eval it and mutate original object
const styles: MakeStyles =
typeof styleRule === 'function' ? (styleRule as MakeStylesStyleFunctionRule<Tokens>)(tokens!!) : styleRule!!;
Expand Down
4 changes: 4 additions & 0 deletions packages/make-styles/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface MakeStylesOptions<Tokens> {
rtl?: boolean;
renderer: MakeStylesRenderer;
tokens: Tokens;
debug?: {
debugId?: string;
tokens?: Record<string, boolean>;
};
}

export type MakeStaticStyles =
Expand Down
2 changes: 2 additions & 0 deletions packages/react-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
"@fluentui/keyboard-key": "^0.2.13",
"@fluentui/react-hooks": "^8.0.0-beta.11",
"@fluentui/react-icons-mdl2": "^1.0.0-beta.13",
"@fluentui/react-make-styles": "^0.2.2",
"@fluentui/react-shared-contexts": "^1.0.0-beta.5",
"@fluentui/react-theme": "^0.3.0",
"@fluentui/react-theme-provider": "^1.0.0-beta.23",
"@fluentui/react-utils": "^0.3.1",
"@fluentui/theme": "^2.0.0-beta.15",
Expand Down
Loading