Skip to content

Commit

Permalink
Staging the react-avatar package; (microsoft#14518)
Browse files Browse the repository at this point in the history
* Adding react-avatar.

* Adding Avatar.

* Updating Avatar to use raw sass.

* blah.

* more updates.

* Changes.

* Shorthand props now work

* more updates.

* Adding PersonaCoin example.

* Cleanup.

* Updating url.

* changes

* more changes.

* Adding button. Renaming handledProp to mappedProp.

* Addressing missing font definitions. Adding stylesheet support to themeprovider.

* Addressing review feedback.

* Merge branch 'master' of https://github.com/microsoft/fluentui into feat/avatar

# Conflicts:
#	apps/test-bundles/package.json
#	packages/fluentui/react-northstar/src/components/Provider/Provider.tsx
#	yarn.lock

* Undoing changes.

* undoing a few more changes.

* Updating react-compose dependency

* Fixing broken things.

* wip

* Update packages/react-compose/src/utils.ts

* converted all components to use react-compose

* wip

* Integrating useStylesheet.

* Removing dupe stylesheets provider.

* Merge branch 'master' of https://github.com/microsoft/fluentui into feat/avatar

# Conflicts:
#	.vscode/settings.json
#	packages/fluentui/react-northstar/src/utils/felaStylisEnhancer.ts
#	packages/react-compose/etc/react-compose.api.md
#	packages/react-compose/package.json
#	packages/react-compose/src/compose.ts
#	packages/react-compose/src/types.ts
#	packages/react-compose/src/utils.ts
#	scripts/package.json
#	yarn.lock

* updated readme

* Change files

* removing private

* Change files

* fixing lint.

* Ensuring tests work.

* Awesome.

* updates.

* yarn updates.

Co-authored-by: Marija Najdova <[email protected]>
  • Loading branch information
2 people authored and levithomason committed Aug 24, 2020
1 parent 8f78cf1 commit 8e55131
Show file tree
Hide file tree
Showing 45 changed files with 882 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "Seeding initial package.",
"packageName": "@fluentui/react-avatar",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-08-14T01:36:08.465Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "Updating readme.",
"packageName": "@fluentui/react-compose",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-08-14T01:32:24.265Z"
}
32 changes: 32 additions & 0 deletions packages/react-avatar/.npmignore
Original file line number Diff line number Diff line change
@@ -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-avatar/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=https://registry.npmjs.org/

8 changes: 8 additions & 0 deletions packages/react-avatar/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const custom = require('@uifabric/build/storybook/webpack.config');

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

addons.setConfig({
showPanel: true,
panelPosition: 'bottom',
});
32 changes: 32 additions & 0 deletions packages/react-avatar/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { initializeIcons } from '@uifabric/icons';
import generateStoriesFromExamples from '@uifabric/build/storybook/generateStoriesFromExamples';
import { configure, addParameters, addDecorator } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import { withA11y } from '@storybook/addon-a11y';
import { withPerformance } from 'storybook-addon-performance';

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

initializeIcons();

const req = require.context('../src', 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);
4 changes: 4 additions & 0 deletions packages/react-avatar/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@fluentui/react-avatar",
"entries": []
}
3 changes: 3 additions & 0 deletions packages/react-avatar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Change Log - @fluentui/react-avatar

This log was last generated on Mon, 23 Mar 2020 18:44:38 GMT and should not be manually modified.
15 changes: 15 additions & 0 deletions packages/react-avatar/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@uifabric/react-avatar

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 Office UI Fabric is subject to the terms listed at https://aka.ms/fabric-assets-license
17 changes: 17 additions & 0 deletions packages/react-avatar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @fluentui/react-avatar

**React Avatar components for [Fluent UI](https://dev.microsoft.com/fluentui)**

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 ReactAvatar components:

```js
import { ComponentName } from '@fluentui/react-avatar';
```

Once the Avatar component graduates to a production release, the component will be available at:

```js
import { ComponentName } from '@fluentui/react';
```
5 changes: 5 additions & 0 deletions packages/react-avatar/config/pre-copy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"copyTo": {
"dist": []
}
}
12 changes: 12 additions & 0 deletions packages/react-avatar/config/tests.js
Original file line number Diff line number Diff line change
@@ -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() });
8 changes: 8 additions & 0 deletions packages/react-avatar/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { createConfig } = require('@uifabric/build/jest/jest-resources');
const path = require('path');

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

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

preset();
64 changes: 64 additions & 0 deletions packages/react-avatar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@fluentui/react-avatar",
"version": "0.1.0",
"description": "React components for building Microsoft web experiences.",
"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",
"bundle": "just-scripts bundle",
"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": {
"@fluentui/react-conformance": "^0.1.0",
"@types/enzyme": "3.10.3",
"@types/enzyme-adapter-react-16": "1.0.3",
"@types/jest": "~24.9.0",
"@types/react": "16.8.25",
"@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/jest-serializer-merge-styles": "^7.0.33",
"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"
},
"dependencies": {
"@fluentui/react-compose": "^0.14.4",
"@fluentui/accessibility": "^0.51.0",
"@fluentui/react-theme-provider": "^0.7.1",
"@fluentui/react-stylesheets": "^0.1.16",
"@uifabric/set-version": "^7.0.19",
"@uifabric/react-hooks": "^7.8.1",
"@uifabric/utilities": "^7.27.1",
"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"
}
}
1 change: 1 addition & 0 deletions packages/react-avatar/src/Avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/Avatar/index';
109 changes: 109 additions & 0 deletions packages/react-avatar/src/components/Avatar/Avatar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Define default variable values
:root {
--avatarSizeSmallest: 20px;
--avatarSizeSmaller: 24px;
--avatarSizeSmall: 28px;
--avatarSizeMedium: 32px;
--avatarSizeLarge: 44px;
--avatarSizeLarger: 64px;
--avatarSizeLargest: 96px;
--avatarBorderColor: transparent;
--avatarBorderWidth: 0;
--avatarBorderRadius: 9999px;

--squareAvatarBorderRadius: 3px;
--statusBorderColor: transparent;
--statusBorderWidth: 2px;
--avatarFill: rgb(232, 232, 232);
}

// Root slot
.root {
position: relative;
background-color: inherit;
display: inline-block;
vertical-align: middle;
flex-shrink: 0;
width: var(--avatarSize, var(--avatarSizeMedium));
height: var(--avatarSize, var(--avatarSizeMedium));
}

// Image slot
.image {
position: absolute;
border-radius: var(--avatarBorderRadius);
top: 0;
left: 0;
width: var(--avatarSize, var(--avatarSizeMedium));
height: var(--avatarSize, var(--avatarSizeMedium));
height: 100%;
object-fit: cover;
vertical-align: top;
}

// Label slot
.label {
display: flex;
align-items: center;
justify-content: center;
background-color: var(--avatarFill);

font-size: calc(var(--avatarSize) / 2.333);
width: var(--avatarSize, var(--avatarSizeMedium));
height: var(--avatarSize, var(--avatarSizeMedium));

vertical-align: top;
text-align: center;
padding: 0px;
border-radius: 99999px;
}

// Status slot
.status {
position: absolute;
bottom: 0;
right: 0;
box-shadow: 0 0 0 var(--statusBorderWidth) var(--statusBorderColor);
}

// Root modifier when props.size_ smallest
._size_smallest {
--avatarSize: var(--avatarSizeSmallest);
}

// Root modifier when props.size_ smaller
._size_smaller {
--avatarSize: var(--avatarSizeSmaller);
}

// Root modifier when props.size_ small
._size_small {
--avatarSize: var(--avatarSizeSmall);
}

// Root modifier when props.size_ large
._size_large {
--avatarSize: var(--avatarSizeLarge);
}

// Root modifier when props.size_ larger
// larger-abc123
._size_larger {
--avatarSize: var(--avatarSizeLarger);
}

// Root modifier when props.size_ largest
._size_largest {
--avatarSize: var(--avatarSizeLargest);
}

// Modifiers
._square {
.image {
border-radius: var(--squareAvatarBorderRadius);
}

.label {
border-radius: var(--squareAvatarBorderRadius);
}
}
39 changes: 39 additions & 0 deletions packages/react-avatar/src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from 'react';
import { Avatar } from './Avatar';
import { StoryExample } from '../utils/StoryExample';

const imageUrl = 'http://www.fillmurray.com/192/192';

export const AvatarCss = () => (
<StoryExample title="Avatar (css)">
<Avatar size="smallest" name="John Doe" status="success" />
<Avatar size="smaller" name="John Doe" status="success" />
<Avatar size="small" name="John Doe" status="success" />
<Avatar name="John Doe" status="success" />
<Avatar size="large" name="Jane Doe" status="error" />
<Avatar size="larger" name="Lorem Ipsum" status="warning" />
<Avatar size="largest" name="Lorem Ipsum" status="warning" />
<Avatar square size="smallest" name="John Doe" status="success" />
<Avatar square size="smaller" name="John Doe" status="success" />
<Avatar square size="small" name="John Doe" status="success" />
<Avatar square name="John Doe" status="success" />
<Avatar square size="large" name="Jane Doe" status="error" />
<Avatar square size="larger" name="Lorem Ipsum" status="warning" />
<Avatar square size="largest" name="Lorem Ipsum" status="warning" />

<Avatar size="smallest" name="John Doe" status="success" image={imageUrl} />
<Avatar size="smaller" name="John Doe" status="success" image={imageUrl} />
<Avatar size="small" name="John Doe" status="success" image={imageUrl} />
<Avatar name="John Doe" status="success" image={imageUrl} />
<Avatar size="large" name="Jane Doe" status="error" image={imageUrl} />
<Avatar size="larger" name="Lorem Ipsum" status="warning" image={imageUrl} />
<Avatar size="largest" name="Lorem Ipsum" status="warning" image={imageUrl} />
<Avatar square size="smallest" name="John Doe" status="success" image={imageUrl} />
<Avatar square size="smaller" name="John Doe" status="success" image={imageUrl} />
<Avatar square size="small" name="John Doe" status="success" image={imageUrl} />
<Avatar square name="John Doe" status="success" image={imageUrl} />
<Avatar square size="large" name="Jane Doe" status="error" image={imageUrl} />
<Avatar square size="larger" name="Lorem Ipsum" status="warning" image={imageUrl} />
<Avatar square size="largest" name="Lorem Ipsum" status="warning" image={imageUrl} />
</StoryExample>
);
Loading

0 comments on commit 8e55131

Please sign in to comment.