Skip to content

Commit

Permalink
Merge branch 'chore/fela-enhancer' of https://github.com/microsoft/fl…
Browse files Browse the repository at this point in the history
…uentui into chore/try-mix-cache-n-stylis

� Conflicts:
�	packages/fluentui/react-northstar/src/utils/felaRenderer.tsx
  • Loading branch information
layershifter committed Mar 30, 2020
2 parents 150d1ac + ed7d95d commit 8f74564
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 90 deletions.
3 changes: 3 additions & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Expose `contentWrapper` shorthand from `AccordionTitle` @silviuavram ([#12265](https://github.com/OfficeDev/office-ui-fabric-react/pull/12265))
- Add `disabled` versions for `Dropdown` and `Input` @silviuavram ([#12250](https://github.com/OfficeDev/office-ui-fabric-react/pull/12250))

### Performance
- Replace `fela-plugin-prexifer` with `stylis` @layershifter ([#12289](https://github.com/OfficeDev/office-ui-fabric-react/pull/12289))

### Documentation
- Adding context menu for table row to example and prototype @kolaps33 ([#12253](https://github.com/OfficeDev/office-ui-fabric-react/pull/12253))

Expand Down
4 changes: 2 additions & 2 deletions packages/fluentui/react-northstar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"fela-plugin-embedded": "^10.6.1",
"fela-plugin-fallback-value": "^10.6.1",
"fela-plugin-placeholder-prefixer": "^10.6.1",
"fela-plugin-prefixer": "^10.6.1",
"fela-plugin-rtl": "^10.6.1",
"inline-style-expand-shorthand": "^1.2.0",
"keyboard-key": "1.0.1",
"lodash": "^4.17.15",
"popper.js": "^1.15.0",
"prop-types": "^15.7.2",
"react-fela": "^10.6.1",
"react-transition-group": "^4.3.0"
"react-transition-group": "^4.3.0",
"stylis": "^3.5.4"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ const accordionTitleStyles: ComponentSlotStylesPrepared<AccordionTitleProps, Acc
cursor: p.disabled ? 'default' : 'pointer',
}),
contentWrapper: ({ props: p }) => ({
display: 'grid',
gridTemplateColumns: `auto ${p.content ? '1fr' : ''}`,
display: ['grid', '-ms-grid'],
gridTemplateColumns: 'auto',
msGridColumns: 'auto',

...(p.content && {
gridTemplateColumns: 'auto 1fr',
msGridColumns: 'auto 1fr',
}),
}),
indicator: ({ props: p, variables: v, rtl }) => ({
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ const checkboxStyles: ComponentSlotStylesPrepared<CheckboxStylesProps, CheckboxV
root: ({ props: p, variables: v, theme: t }): ICSSInJSStyle => ({
position: 'relative',

display: 'inline-grid',
display: ['inline-grid', '-ms-inline-grid'],
gridTemplateColumns: `1fr ${v.gap} auto`,
// IE11: Gap is done via virtual column as in autoprefixer
gridTemplateColumns: p.labelPosition === 'start' ? `1fr ${v.gap} auto` : `auto ${v.gap} 1fr`,
msGridColumns: `auto ${v.gap} 1fr`,

...(p.labelPosition === 'start' && {
gridTemplateColumns: `1fr ${v.gap} auto`,
msGridColumns: `1fr ${v.gap} auto`,
}),

cursor: 'pointer',
outline: 0,

Expand Down Expand Up @@ -82,8 +89,15 @@ const checkboxStyles: ComponentSlotStylesPrepared<CheckboxStylesProps, CheckboxV
}),

checkbox: ({ props: p, variables: v }): ICSSInJSStyle => ({
gridColumn: p.labelPosition === 'start' ? 3 : 1,
'-ms-grid-row-align': 'center',
msGridRowAlign: 'center',
gridColumn: 1,
msGridColumn: 1,

...(p.labelPosition === 'start' && {
gridColumn: 3,
msGridColumn: 3,
}),

boxShadow: 'unset',
width: pxToRem(16),
height: pxToRem(16),
Expand Down Expand Up @@ -120,8 +134,15 @@ const checkboxStyles: ComponentSlotStylesPrepared<CheckboxStylesProps, CheckboxV
}),

toggle: ({ props: p, variables: v }): ICSSInJSStyle => ({
'-ms-grid-row-align': 'center',
gridColumn: p.labelPosition === 'start' ? 3 : 1,
msGridRowAlign: 'center',
gridColumn: 1,
msGridColumn: 1,

...(p.labelPosition === 'start' && {
gridColumn: 3,
msGridColumn: 3,
}),

boxShadow: 'unset',
boxSizing: 'border-box',

Expand Down Expand Up @@ -170,7 +191,14 @@ const checkboxStyles: ComponentSlotStylesPrepared<CheckboxStylesProps, CheckboxV

label: ({ props: p }): ICSSInJSStyle => ({
display: 'block', // IE11: should be forced to be block, as inline-block is not supported
gridColumn: p.labelPosition === 'start' ? 1 : 3,

gridColumn: 3,
msGridColumn: 3,

...(p.labelPosition === 'start' && {
gridColumn: 1,
msGridColumn: 1,
}),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ export default {
padding: v.rootPadding,
position: 'relative',
width: v.rootWidth,
display: 'grid',

display: ['grid', '-ms-grid'],
gridTemplateColumns: '1fr auto',
msGridColumns: '1fr auto',

boxShadow: v.boxShadow,
color: v.foregroundColor,
}),

footer: (): ICSSInJSStyle => ({
gridColumn: '1 / -1',
gridRow: 3,
msGridRow: 3,
}),

actions: (): ICSSInJSStyle => ({
Expand All @@ -30,24 +34,34 @@ export default {

content: ({ variables: v }: DialogStyleParams): ICSSInJSStyle => ({
margin: v.contentMargin,

gridColumn: '1 / span 2',
gridRow: 2,

msGridColumn: 1,
msGridColumnSpan: 2,
msGridRow: 2,

justifySelf: 'left',
width: '100%',
}),

header: ({ variables: v }: DialogStyleParams): ICSSInJSStyle => ({
margin: v.headerMargin,
gridRow: 1,
msGridRow: 1,
gridColumn: 1,
msGridColumn: 1,
justifySelf: 'left',
fontSize: v.headerFontSize,
fontWeight: v.headerFontWeight,
}),

headerAction: ({ variables: v }: DialogStyleParams) => ({
gridRow: 1,
msGridRow: 1,
gridColumn: 2,
msGridColumn: 2,
color: v.foregroundColor,
margin: v.headerActionMargin,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const formStyles: ComponentSlotStylesPrepared<FormProps, any> = {
root: ({ props, variables }): ICSSInJSStyle => ({
height: '100%',
width: '100%',
display: 'grid',
display: ['grid', '-ms-grid'],
gridTemplateColumns: '1fr',
msGridColumns: '1fr',
justifyContent: 'space-evenly',
gridGap: pxToRem(20),
justifyItems: 'start',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ const gridStyles: ComponentSlotStylesPrepared<GridProps, GridVariables> = {
width,
padding,
gridGap,
display: 'grid',
display: ['grid', '-ms-grid'],
justifyContent: 'space-evenly',

...(rows && !columns && { gridAutoFlow: 'column' }),
...(rows && { gridTemplateRows: getCSSTemplateValue(rows) }),
...(columns && { gridTemplateColumns: getCSSTemplateValue(columns) }),
...(rows && {
gridTemplateRows: getCSSTemplateValue(rows),
msGridRows: getCSSTemplateValue(rows),
}),
...(columns && {
gridTemplateColumns: getCSSTemplateValue(columns),
msGridColumns: getCSSTemplateValue(columns),
}),

'& > *': { outlineOffset: '-3px' },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const layoutStyles: ComponentSlotStylesPrepared<LayoutProps> = {
...(debug && debugRoot()),
justifyItems,
alignItems,
display: 'grid',
display: ['grid', '-ms-grid'],
[vertical ? 'gridTemplateRows' : 'gridTemplateColumns']: [
// Heads up!
// IE11 Doesn't support grid-gap, insert virtual columns instead
Expand Down Expand Up @@ -60,7 +60,7 @@ const layoutStyles: ComponentSlotStylesPrepared<LayoutProps> = {
main: ({ props: p }): ICSSInJSStyle => ({
...(p.debug && debugArea()),
alignItems: 'center',
display: 'grid',
display: ['grid', '-ms-grid'],
[p.vertical ? '-ms-grid-row' : '-ms-grid-column']: countTrue([p.start, p.start && p.gap, p.main]),
...p.mainCSS,
}),
Expand Down
6 changes: 2 additions & 4 deletions packages/fluentui/react-northstar/src/utils/felaRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { createRenderer as createFelaRenderer } from 'fela';
import felaPluginEmbedded from 'fela-plugin-embedded';
import felaPluginFallbackValue from 'fela-plugin-fallback-value';
import felaPluginPlaceholderPrefixer from 'fela-plugin-placeholder-prefixer';
import felaPluginPrefixer from 'fela-plugin-prefixer';
import felaPluginRtl from 'fela-plugin-rtl';

import felaDisableAnimationsPlugin from './felaDisableAnimationsPlugin';
import felaFocusVisibleEnhancer from './felaFocusVisibleEnhancer';
import felaInvokeKeyframesPlugin from './felaInvokeKeyframesPlugin';
import felaRuleCacheEnhancer from './felaRuleCacheEnhancer';
import felaSanitizeCss from './felaSanitizeCssPlugin';
import felaStylisEnhancer from './felaStylisEnhancer';

let felaDevMode = false;

Expand Down Expand Up @@ -52,7 +52,7 @@ const filterClassName = (className: string): boolean =>
const rendererConfig = {
devMode: felaDevMode,
filterClassName,
enhancers: [felaFocusVisibleEnhancer, felaRuleCacheEnhancer],
enhancers: [felaFocusVisibleEnhancer, felaStylisEnhancer, felaRuleCacheEnhancer],
plugins: [
felaDisableAnimationsPlugin(),

Expand All @@ -65,8 +65,6 @@ const rendererConfig = {
felaPluginPlaceholderPrefixer(),
felaInvokeKeyframesPlugin(),
felaPluginEmbedded(),
felaPluginPrefixer(),


// Heads up!
// This is required after fela-plugin-prefixer to resolve the array of fallback values prefixer produces.
Expand Down
31 changes: 31 additions & 0 deletions packages/fluentui/react-northstar/src/utils/felaStylisEnhancer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { RULE_TYPE } from 'fela-utils';
// @ts-ignore
import Stylis from 'stylis';

import { Renderer, RendererChange } from './types';

// We use Stylis only for vendor prefixing, all other capabilities are disabled
const stylis = new Stylis({
cascade: false,
compress: false,
global: false,
keyframe: false,
preserve: false,
semicolon: false,
});

const felaStylisEnhancer = (renderer: Renderer) => ({
...renderer,
_emitChange: (change: RendererChange) => {
if (change.type === RULE_TYPE) {
const prefixed: string = stylis('', change.declaration);

// Fela uses objects by references, it's safe to override properties
change.declaration = prefixed.slice(1, -1);
}

renderer._emitChange(change);
},
});

export default felaStylisEnhancer;
16 changes: 16 additions & 0 deletions packages/fluentui/react-northstar/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IRenderer } from 'fela';

export type Renderer = IRenderer & {
cache: Record<string, RendererChange>;
_emitChange?: (change: RendererChange) => void;
};

export type RendererChange = {
type: 'RULE' | 'KEYFRAME' | 'FONT' | 'STATIC' | 'CLEAR';
className: string;
selector: string;
declaration: Object;
pseudo: string;
media: string;
support: string;
};
Loading

0 comments on commit 8f74564

Please sign in to comment.