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(icons): add @fluentui/react-icons package #12608

Merged
merged 22 commits into from Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/office-ui-fabric-react/package.json
Expand Up @@ -71,6 +71,7 @@
"sinon": "^4.1.3"
},
"dependencies": {
"@fluentui/react-icons": "^0.1.0",
"@fluentui/react-focus": "^7.1.12",
"@microsoft/load-themed-styles": "^1.10.26",
"@uifabric/foundation": "^7.5.24",
Expand Down
Expand Up @@ -5,11 +5,13 @@ import { IDocPageProps } from '../../common/DocPage.types';
import { IconSvgExample } from './examples/Icon.Svg.Example';
import { IconColorExample } from './examples/Icon.Color.Example';
import { IconImageSheetExample } from './examples/Icon.ImageSheet.Example';
import { IconSvgFactoryExample } from './examples/Icon.SvgFactory.Example';

const IconBasicExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Icon/examples/Icon.Basic.Example.tsx') as string;
const IconSvgExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Icon/examples/Icon.Svg.Example.tsx') as string;
const IconColorExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Icon/examples/Icon.Color.Example.tsx') as string;
const IconImageSheetExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Icon/examples/Icon.ImageSheet.Example.tsx') as string;
const IconSvgFactoryExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Icon/examples/Icon.SvgFactory.Example.tsx') as string;

export const IconPageProps: IDocPageProps = {
title: 'Icon',
Expand All @@ -36,6 +38,11 @@ export const IconPageProps: IDocPageProps = {
code: IconImageSheetExampleCode,
view: <IconImageSheetExample />,
},
{
title: 'Icon using svg factory',
code: IconSvgFactoryExampleCode,
view: <IconSvgFactoryExample />,
},
],
overview: require<string>('!raw-loader!office-ui-fabric-react/src/components/Icon/docs/IconOverview.md'),
bestPractices: '',
Expand Down
@@ -0,0 +1,25 @@
import { IIconStyleProps } from './Icon.types';
import { ISvgIconStyles } from './SvgIcon.types';
import { mergeStyleSets } from '../../Styling';

/** Class names used in themeable and non-themeable Icon components */
export const classNames = mergeStyleSets({
root: {
selectors: {
svg: {
height: 50,
width: 50,
},
},
},
});
/** Class name used only in non-themeable Icon components */
export const MS_ICON = 'ms-Icon';

export const getStyles = (props: IIconStyleProps): ISvgIconStyles => {
const { className, iconClassName, styles } = props;

return {
root: [classNames.root, iconClassName, className, styles && styles.root],
};
};
@@ -0,0 +1,13 @@
import * as React from 'react';
import { IStyle } from 'office-ui-fabric-react/lib/Styling';

export interface ISvgIconProps extends React.HTMLAttributes<HTMLElement> {
/**
* Custom class to style the icon.
*/
className?: string;
}

export interface ISvgIconStyles {
root?: IStyle;
}
@@ -0,0 +1,30 @@
// tslint:disable:jsx-wrap-multiline max-line-length
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
import * as React from 'react';
import { OneDriveIcon, YammerIcon, BorderBlindsIcon } from '@fluentui/react-icons';
import { mergeStyles } from 'office-ui-fabric-react/lib/Styling';

const iconClass = mergeStyles({
fontSize: 50,
height: 50,
width: 50,
margin: '0 25px',
});

export const IconSvgFactoryExample: React.FunctionComponent = () => {
return (
<div>
<OneDriveIcon className={iconClass} />
<YammerIcon
className={mergeStyles(iconClass, {
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
fill: 'red',
selectors: {
'.thing': {
fill: 'green',
},
},
})}
/>
<BorderBlindsIcon className={iconClass} color3="pink" />
</div>
);
};
32 changes: 32 additions & 0 deletions packages/react-icons/.npmignore
@@ -0,0 +1,32 @@
*.api.json
*.config.js
*.log
*.nuspec
*.test.*
*.yml
.editorconfig
.gitattributes
.gitignore
.vscode
coverage
dist-storybook
dist/*.stats.html
dist/*.stats.json
dist/demo*.*
fabric-test*
gulpfile.js
images
index.html
jsconfig.json
node_modules
results
src/**/*
!src/**/examples/*.tsx
!src/**/docs/**/*.md
!src/**/*.types.ts
temp
tsconfig.json
tsd.json
tslint.json
typings
visualtests
2 changes: 2 additions & 0 deletions packages/react-icons/.npmrc
@@ -0,0 +1,2 @@
registry=https://registry.npmjs.org/

8 changes: 8 additions & 0 deletions packages/react-icons/.storybook/main.js
@@ -0,0 +1,8 @@
const custom = require('@uifabric/build/storybook/webpack.config');

module.exports = {
webpackFinal: config => {
return custom({ config });
},
addons: ['@storybook/addon-a11y/register'],
};
6 changes: 6 additions & 0 deletions packages/react-icons/.storybook/manager.js
@@ -0,0 +1,6 @@
import { addons } from '@storybook/addons';

addons.setConfig({
showPanel: true,
panelPosition: 'right',
});
25 changes: 25 additions & 0 deletions packages/react-icons/.storybook/preview.js
@@ -0,0 +1,25 @@
import generateStoriesFromExamples from '@uifabric/build/storybook/generateStoriesFromExamples';
import { configure, addParameters, addDecorator } from '@storybook/react';
import { withA11y } from '@storybook/addon-a11y';

addDecorator(withA11y());
addParameters({
a11y: {
manual: true,
},
});

const req = require.context('../src/components', true, /\.stories\.tsx$/);

function loadStories() {
const stories = new Map();

req.keys().forEach(key => {
generateStoriesFromExamples({ key, req, stories });
});

// convert stories Set to array
return [...stories.values()];
}

configure(loadStories, module);
15 changes: 15 additions & 0 deletions packages/react-icons/LICENSE
@@ -0,0 +1,15 @@
@fluentui/react-icons

Copyright (c) Microsoft Corporation

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note: Usage of the fonts and icons referenced in Fluent UI React is subject to the terms listed at https://aka.ms/fluentui-assets-license
11 changes: 11 additions & 0 deletions packages/react-icons/README.md
@@ -0,0 +1,11 @@
# @fluentui/react-icons

**ReactIcons components for [Office UI Fabric React](https://dev.microsoft.com/fabric)**
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

These are not production-ready components and **should never be used in product**. This space is useful for testing new components whose APIs might change before final release.

To import ReactIcons components:

```js
import { ComponentName } from '@fluentui/react-icons';
```
12 changes: 12 additions & 0 deletions packages/react-icons/config/tests.js
@@ -0,0 +1,12 @@
/** Jest test setup file. */

const { configure } = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');

// Mock requestAnimationFrame for React 16+.
global.requestAnimationFrame = callback => {
setTimeout(callback, 0);
};

// Configure enzyme.
configure({ adapter: new Adapter() });
12 changes: 12 additions & 0 deletions packages/react-icons/jest.config.js
@@ -0,0 +1,12 @@
let { createConfig, resolveMergeStylesSerializer } = require('@uifabric/build/jest/jest-resources');
let path = require('path');

const config = createConfig({
setupFiles: [path.resolve(path.join(__dirname, 'config', 'tests.js'))],

moduleNameMapper: {},

snapshotSerializers: [resolveMergeStylesSerializer()],
});

module.exports = config;
3 changes: 3 additions & 0 deletions packages/react-icons/just.config.ts
@@ -0,0 +1,3 @@
const { preset } = require('@uifabric/build');

preset();
59 changes: 59 additions & 0 deletions packages/react-icons/package.json
@@ -0,0 +1,59 @@
{
"name": "@fluentui/react-icons",
"version": "0.1.0",
"description": "React components for building web experiences.",
"private": true,
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"typings": "lib/index.d.ts",
"sideEffects": [
"lib/version.js"
],
"repository": {
"type": "git",
"url": "https://github.com/microsoft/fluentui"
},
"license": "MIT",
"scripts": {
"build": "just-scripts build",
"clean": "just-scripts clean",
"code-style": "just-scripts code-style",
"just": "just-scripts",
"lint": "just-scripts lint",
"start": "just-scripts dev:storybook",
"start-test": "just-scripts jest-watch",
"test": "just-scripts test",
"update-api": "just-scripts update-api",
"update-snapshots": "just-scripts jest -u"
},
"devDependencies": {
"@types/enzyme": "3.10.3",
"@types/enzyme-adapter-react-16": "1.0.3",
"@types/es6-promise": "0.0.32",
"@types/jest": "~24.9.0",
"@types/react": "16.8.11",
"@types/react-dom": "16.8.4",
"@types/react-test-renderer": "^16.0.0",
"@types/webpack-env": "1.15.1",
"@uifabric/build": "^7.0.0",
"@uifabric/tslint-rules": "^7.1.2",
"enzyme": "~3.10.0",
"enzyme-adapter-react-16": "^1.15.0",
"es6-weak-map": "^2.0.2",
"react": "16.8.6",
"react-app-polyfill": "~1.0.1",
"react-dom": "16.8.6",
"react-test-renderer": "^16.3.0",
"typescript-plugin-css-modules": "^2.2.0"
},
"dependencies": {
"@uifabric/set-version": "^7.0.9",
"tslib": "^1.10.0"
},
"peerDependencies": {
"@types/react": ">=16.8.0 <17.0.0",
"@types/react-dom": ">=16.8.0 <17.0.0",
"react": ">=16.8.0 <17.0.0",
"react-dom": ">=16.8.0 <17.0.0"
}
}
43 changes: 43 additions & 0 deletions packages/react-icons/src/components/BorderBlindsIcon.tsx
@@ -0,0 +1,43 @@
import * as React from 'react';
import createSvgIconWithRoot from '../utils/createSvgIconWithRoot';
import { mergeStyles } from 'office-ui-fabric-react/src/Styling';

const BorderBlindsIcon = createSvgIconWithRoot<{ color1?: string; color2?: string; color3?: string }>({
// TODO: convert classNames.svg to selector to selector

children: ({ classNames, props, processedRootProps }) => {
const { className, ...restRootPRops } = processedRootProps;
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
const { color1 = 'red', color2 = 'green', color3 = 'blue' } = props;

const classesOverrides = mergeStyles(className, {
width: 50,
height: 50,
selectors: {
'.borderblinds-part1': {
fill: color1,
},
'.borderblinds-part2': {
fill: color2,
},
'.borderblinds-part3': {
fill: color3,
},
},
});

return (
<span {...restRootPRops} className={classesOverrides}>
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
<svg viewBox="0 0 40 40">
<g transform="scale(0.03125 0.03125)">
<path className="borderblinds-part1" d="M0 192l320-128v768l-320 128z" />
<path className="borderblinds-part2" d="M384 32l320 192v736l-320-160z" />
<path className="borderblinds-part3" d="M768 224l256-192v768l-256 192z" />
</g>
</svg>
</span>
);
},
displayName: 'BorderBlindsIcon',
});

export default BorderBlindsIcon;
Copy link
Member

Choose a reason for hiding this comment

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

Have we discussed whether we want to use default or named exports in new code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, I just used whatever I was used to :S Let me know what makes more sense and will update it..

Copy link
Member

@dzearing dzearing Apr 9, 2020

Choose a reason for hiding this comment

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

Original thinking with not exporting default was:

A downstream index.ts file might do something like:

export * from './BorderBlindsIcon';

Which would not include the default export, but only named ones. That said, we have seen concerns multiple times about export *. And there is NO friction in exporting { default as Foo } explicitly; explicit exports are better anyway in that we don't accidentally leak something unintentionally.

So my 2c is "it's fine".

15 changes: 15 additions & 0 deletions packages/react-icons/src/components/OneDriveIcon.tsx
@@ -0,0 +1,15 @@
import * as React from 'react';
import createSvgIcon from '../utils/createSvgIcon';

const OneDriveIcon = createSvgIcon({
svg: ({ classNames }) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0,0,2048,2048">
Copy link
Member

Choose a reason for hiding this comment

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

Should classNames get injected on the root?

Copy link
Contributor Author

@mnajdova mnajdova Apr 9, 2020

Choose a reason for hiding this comment

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

createSvgIcon is doing that. I have two alternatives of the factory once that is for injecting only the svg and another one that allows user to have custom props and define the root element too. Let's see if we will need the both or choose one

<g fill="#1B559B">
<path d="M 1860 1196 q 53 10 94 37 q 18 12 35 29 q 16 16 30 40 q 13 23 21 53 q 8 30 8 68 q 0 37 -10 75 q -11 38 -34 69 q -23 31 -58 51 q -36 20 -86 20 h -1079 q -78 0 -131 -24 q -54 -25 -87 -65 q -34 -40 -49 -91 q -15 -52 -15 -107 q 0 -46 12 -81 q 11 -35 31 -61 q 19 -27 43 -45 q 24 -19 50 -31 q 60 -29 136 -35 q 0 -1 4 -26 q 3 -25 16 -61 q 12 -37 36 -80 q 24 -43 64 -79 q 39 -37 98 -61 q 59 -25 141 -25 q 57 0 103 15 q 45 15 81 38 q 35 23 62 52 q 26 28 44 55 q 18 -10 42 -18 q 20 -7 48 -12 q 27 -6 60 -6 q 40 0 91 15 q 50 14 94 48 q 44 33 75 88 q 30 55 30 136 m -1463 174 q 0 53 10 99 q 10 46 29 86 h -170 q -52 0 -100 -23 q -48 -23 -85 -61 q -37 -38 -59 -87 q -22 -50 -22 -104 q 0 -49 11 -87 q 10 -38 27 -66 q 17 -29 39 -49 q 21 -21 44 -35 q 53 -33 121 -41 q -1 -9 -1 -18 q -1 -9 -1 -17 q 0 -72 27 -134 q 27 -63 73 -110 q 45 -47 106 -74 q 60 -27 127 -27 q 36 0 66 7 q 29 6 51 14 q 25 10 45 21 q 27 -48 65 -89 q 37 -41 84 -71 q 46 -30 101 -47 q 55 -17 115 -17 q 39 0 80 8 q 41 7 83 24 q 72 28 121 71 q 49 42 81 90 q 32 47 49 94 q 16 46 22 82 q -23 2 -43 5 q -21 3 -40 8 q -66 -69 -148 -104 q -82 -36 -177 -36 q -76 0 -136 17 q -60 17 -106 45 q -47 28 -81 64 q -34 36 -58 75 q -24 38 -39 76 q -15 37 -23 67 q -51 12 -102 38 q -52 26 -93 68 q -42 42 -67 101 q -26 59 -26 137" />
</g>
</svg>
),
displayName: 'OneDriveIcon',
});

export default OneDriveIcon;
15 changes: 15 additions & 0 deletions packages/react-icons/src/components/YammerIcon.tsx
@@ -0,0 +1,15 @@
import * as React from 'react';
import createSvgIcon from '../utils/createSvgIcon';

const YammerIcon = createSvgIcon({
svg: ({ classNames }) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0,0,2048,2048">
<g className="thing">
Copy link
Member

@dzearing dzearing Apr 8, 2020

Choose a reason for hiding this comment

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

className="thing", also classNames doesn't seem to be used.

Copy link
Member

Choose a reason for hiding this comment

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

I know this className is being used in an example, but this doesn't seem like a good pattern to demonstrate in general. Maybe find another way to re-style the element for the example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I just copied this examples from the Icon.Svg.Example.tsx. Will create new example with showcase of how the things inside the svgs can be styled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored and improved examples. Please take a look.

<path d="M 1887 888 q 33 8 54 34 q 21 26 21 61 q 0 35 -22 62 q -23 26 -57 31 q -57 0 -121 -2 q -64 -3 -128 -7 q -64 -5 -122 -11 q -59 -7 -104 -16 q -45 -9 -72 -20 q -27 -12 -27 -26 q 0 -13 37 -26 q 37 -13 94 -24 q 57 -12 126 -22 q 68 -11 131 -18 q 63 -8 112 -12 q 48 -4 66 -4 m -163 549 q 17 14 26 34 q 9 20 9 41 q 0 21 -8 39 q -8 17 -21 30 q -14 13 -31 20 q -17 7 -36 7 q -10 0 -18 -2 q -8 -2 -19 -8 q -15 -8 -54 -34 q -39 -26 -88 -61 q -50 -35 -104 -76 q -54 -41 -98 -78 q -45 -37 -74 -67 q -29 -30 -29 -44 q 0 -8 9 -10 q 8 -3 19 -3 q 22 0 57 9 q 34 9 77 25 q 42 15 91 36 q 48 20 98 44 q 50 23 100 49 q 49 25 94 49 m 0 -901 q -67 37 -144 75 q -77 38 -149 69 q -73 30 -132 50 q -60 19 -93 19 q -11 0 -19 -2 q -8 -3 -8 -10 q 0 -14 29 -44 q 29 -30 74 -67 q 44 -38 98 -78 q 54 -41 104 -76 q 49 -36 88 -62 q 39 -26 54 -34 q 11 -6 20 -8 q 8 -2 18 -2 q 18 0 36 8 q 17 7 30 20 q 13 12 21 30 q 8 17 8 38 q 0 21 -9 41 q -9 19 -26 33 m -1191 823 l -430 -1051 q -6 -16 -6 -33 q 0 -20 8 -38 q 7 -19 21 -33 q 13 -15 33 -24 q 19 -9 42 -9 q 30 0 56 16 q 26 16 40 44 l 343 866 h 4 l 326 -860 q 11 -29 37 -46 q 25 -18 56 -18 q 22 0 40 9 q 18 8 31 22 q 13 13 21 31 q 7 17 7 36 q 0 14 -5 31 l -462 1154 q -30 74 -62 136 q -32 62 -76 107 q -44 44 -105 69 q -62 24 -151 24 q -28 0 -57 -2 q -30 -3 -54 -12 q -24 -10 -39 -28 q -16 -19 -16 -52 q 0 -21 8 -38 q 8 -17 21 -29 q 13 -12 30 -18 q 17 -6 35 -6 q 1 0 9 1 q 7 0 17 1 q 10 0 19 1 q 9 0 14 0 q 48 0 84 -15 q 36 -15 65 -46 q 28 -31 51 -78 q 22 -48 45 -112" />
</g>
</svg>
),
displayName: 'YammerIcon',
});

export default YammerIcon;
5 changes: 5 additions & 0 deletions packages/react-icons/src/index.ts
@@ -0,0 +1,5 @@
import './version';

export { default as OneDriveIcon } from './components/OneDriveIcon';
export { default as YammerIcon } from './components/YammerIcon';
export { default as BorderBlindsIcon } from './components/BorderBlindsIcon';