Skip to content

Commit

Permalink
react-card - Phase 1 (#19646)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Varholak <[email protected]>
  • Loading branch information
andrefcdias and varholak-peter authored Sep 14, 2021
1 parent 9cee1b1 commit e870763
Show file tree
Hide file tree
Showing 53 changed files with 940 additions and 48 deletions.
2 changes: 1 addition & 1 deletion apps/perf-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@fluentui/make-styles": "9.0.0-alpha.31",
"@fluentui/react": "^8.34.1",
"@fluentui/react-avatar": "9.0.0-alpha.78",
"@fluentui/react-button": "9.0.0-alpha.84",
"@fluentui/react-button": "^9.0.0-alpha.83",
"@fluentui/react-provider": "9.0.0-alpha.75",
"@fluentui/react-tabs": "^1.0.0-beta.156",
"@fluentui/react-theme": "9.0.0-alpha.22",
Expand Down
6 changes: 3 additions & 3 deletions apps/vr-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@fluentui/react": "^8.34.1",
"@fluentui/react-accordion": "9.0.0-alpha.74",
"@fluentui/react-avatar": "9.0.0-alpha.78",
"@fluentui/react-button": "9.0.0-alpha.84",
"@fluentui/react-card": "9.0.0-alpha.0",
"@fluentui/react-button": "^9.0.0-alpha.83",
"@fluentui/react-card": "^9.0.0-alpha.0",
"@fluentui/react-divider": "9.0.0-alpha.65",
"@fluentui/react-experiments": "^8.3.10",
"@fluentui/react-hooks": "^8.3.2",
Expand All @@ -38,7 +38,7 @@
"@fluentui/react-slider": "9.0.0-alpha.3",
"@fluentui/react-switch": "9.0.0-alpha.2",
"@fluentui/react-tabs": "^1.0.0-beta.156",
"@fluentui/react-text": "9.0.0-alpha.13",
"@fluentui/react-text": "^9.0.0-alpha.12",
"@fluentui/react-theme": "9.0.0-alpha.22",
"@fluentui/scripts": "^1.0.0",
"@fluentui/storybook": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Phase 1 release",
"packageName": "@fluentui/react-card",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add Card to unstable components",
"packageName": "@fluentui/react-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 0 additions & 1 deletion packages/react-card/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.cache/
.storybook/
.vscode/
bundle-size/
Expand Down
5 changes: 4 additions & 1 deletion packages/react-card/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const rootMain = require('../../../.storybook/main');

module.exports = /** @type {Pick<import('../../../.storybook/main').StorybookConfig,'addons'|'stories'|'webpackFinal'>} */ ({
module.exports = /** @type {Omit<import('../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
stories: [...rootMain.stories, '../src/**/*.stories.mdx', '../src/**/*.stories.@(ts|tsx)'],
addons: [...rootMain.addons],
webpackFinal: (config, options) => {
const localConfig = { ...rootMain.webpackFinal(config, options) };

// add your own webpack tweaks if needed

return localConfig;
},
});
Binary file added packages/react-card/assets/ai_deck_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/react-card/assets/avatar_elvia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/react-card/assets/avatar_mauricio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/react-card/assets/doc_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/react-card/assets/powerpoint_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/react-card/assets/sales_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/react-card/assets/word_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/react-card/config/api-extractor.local.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "./api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist/<unscopedPackageName>/src/index.d.ts"
"mainEntryPointFilePath": "<projectFolder>/dist/packages/<unscopedPackageName>/src/index.d.ts"
}
101 changes: 98 additions & 3 deletions packages/react-card/etc/react-card.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import type { ComponentPropsCompat } from '@fluentui/react-utilities';
import type { ComponentStateCompat } from '@fluentui/react-utilities';
import * as React_2 from 'react';
import type { ShorthandPropsCompat } from '@fluentui/react-utilities';

// @public
export const Card: React_2.ForwardRefExoticComponent<CardProps & React_2.RefAttributes<HTMLElement>>;
Expand All @@ -15,14 +16,81 @@ export const Card: React_2.ForwardRefExoticComponent<CardProps & React_2.RefAttr
export type CardDefaultedProps = never;

// @public
export interface CardProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
export const CardFooter: React_2.ForwardRefExoticComponent<CardFooterProps & React_2.RefAttributes<HTMLElement>>;

// @public
export type CardFooterDefaultedProps = never;

// @public
export interface CardFooterProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
action?: ShorthandPropsCompat<React_2.HTMLAttributes<HTMLElement>>;
}

// @public
export type CardShorthandProps = never;
export type CardFooterShorthandProps = 'action';

// @public
export const cardFooterShorthandProps: CardFooterShorthandProps[];

// @public
export const cardShorthandProps: CardShorthandProps[];
export interface CardFooterState extends ComponentStateCompat<CardFooterProps, CardFooterShorthandProps, CardFooterDefaultedProps> {
ref: React_2.Ref<HTMLElement>;
}

// @public
export const CardHeader: React_2.ForwardRefExoticComponent<CardHeaderProps & React_2.RefAttributes<HTMLElement>>;

// @public
export type CardHeaderDefaultedProps = never;

// @public
export interface CardHeaderProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
action?: ShorthandPropsCompat<React_2.HTMLAttributes<HTMLElement>>;
content?: ShorthandPropsCompat<React_2.HTMLAttributes<HTMLElement>>;
description: ShorthandPropsCompat<React_2.HTMLAttributes<HTMLElement>>;
header: ShorthandPropsCompat<React_2.HTMLAttributes<HTMLElement>>;
image: ShorthandPropsCompat<React_2.ImgHTMLAttributes<HTMLImageElement>>;
}

// @public
export type CardHeaderShorthandProps = 'image' | 'content' | 'header' | 'description' | 'action';

// @public
export const cardHeaderShorthandPropsCompat: CardHeaderShorthandProps[];

// @public
export interface CardHeaderState extends ComponentStateCompat<CardHeaderProps, CardHeaderShorthandProps> {
ref: React_2.Ref<HTMLElement>;
}

// @public
export const CardPreview: React_2.ForwardRefExoticComponent<CardPreviewProps & React_2.RefAttributes<HTMLElement>>;

// @public
export type CardPreviewDefaultedProps = never;

// @public
export interface CardPreviewProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
logo?: ShorthandPropsCompat<React_2.ImgHTMLAttributes<HTMLImageElement>>;
}

// @public
export type CardPreviewShorthandProps = 'logo';

// @public
export const cardPreviewShorthandPropsCompat: CardPreviewShorthandProps[];

// @public
export interface CardPreviewState extends ComponentStateCompat<CardPreviewProps, CardPreviewShorthandProps, CardPreviewDefaultedProps> {
ref: React_2.Ref<HTMLElement>;
}

// @public
export interface CardProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
}

// @public
export type CardShorthandProps = never;

// @public
export interface CardState extends CardProps, ComponentStateCompat<CardProps, CardShorthandProps, CardDefaultedProps> {
Expand All @@ -32,9 +100,36 @@ export interface CardState extends CardProps, ComponentStateCompat<CardProps, Ca
// @public
export const renderCard: (state: CardState) => JSX.Element;

// @public
export const renderCardFooter: (state: CardFooterState) => JSX.Element;

// @public
export const renderCardHeader: (state: CardHeaderState) => JSX.Element;

// @public
export const renderCardPreview: (state: CardPreviewState) => JSX.Element;

// @public
export const useCard: (props: CardProps, ref: React_2.Ref<HTMLElement>, defaultProps?: CardProps | undefined) => CardState;

// @public
export const useCardFooter: (props: CardFooterProps, ref: React_2.Ref<HTMLElement>, defaultProps?: CardFooterProps | undefined) => CardFooterState;

// @public
export const useCardFooterStyles: (state: CardFooterState) => CardFooterState;

// @public
export const useCardHeader: (props: CardHeaderProps, ref: React_2.Ref<HTMLElement>, defaultProps?: CardHeaderProps | undefined) => CardHeaderState;

// @public
export const useCardHeaderStyles: (state: CardHeaderState) => CardHeaderState;

// @public
export const useCardPreview: (props: CardPreviewProps, ref: React_2.Ref<HTMLElement>, defaultProps?: CardPreviewProps | undefined) => CardPreviewState;

// @public
export const useCardPreviewStyles: (state: CardPreviewState) => CardPreviewState;

// @public
export const useCardStyles: (state: CardState) => CardState;

Expand Down
8 changes: 5 additions & 3 deletions packages/react-card/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fluentui/react-card",
"version": "9.0.0-alpha.0",
"private": true,
"private": false,
"description": "Card container components for Fluent UI React.",
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
Expand All @@ -21,8 +21,8 @@
"start": "yarn storybook",
"test": "jest",
"docs": "api-extractor run --config=config/api-extractor.local.json --local",
"build:local": "tsc -p . --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output dist/react-card/src && yarn docs",
"storybook": "start-storybook"
"build:local": "tsc -p . --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-card/src && yarn docs",
"storybook": "start-storybook -s assets"
},
"devDependencies": {
"@fluentui/babel-make-styles": "9.0.0-alpha.46",
Expand All @@ -31,6 +31,8 @@
"@fluentui/react-conformance": "^0.5.0",
"@fluentui/react-conformance-make-styles": "9.0.0-alpha.8",
"@fluentui/scripts": "^1.0.0",
"@fluentui/react-text": "^9.0.0-alpha.12",
"@fluentui/react-button": "^9.0.0-alpha.83",
"@types/enzyme": "3.10.3",
"@types/enzyme-adapter-react-16": "1.0.3",
"@types/react": "16.9.42",
Expand Down
1 change: 1 addition & 0 deletions packages/react-card/src/CardFooter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/CardFooter/index';
1 change: 1 addition & 0 deletions packages/react-card/src/CardHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/CardHeader/index';
1 change: 1 addition & 0 deletions packages/react-card/src/CardPreview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/CardPreview/index';
118 changes: 118 additions & 0 deletions packages/react-card/src/components/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import * as React from 'react';
import { Body, Caption } from '@fluentui/react-text';
import { Button } from '@fluentui/react-button';
import {
Open16Regular,
ArrowReply16Regular,
DismissSquare20Regular,
MoreHorizontal16Regular,
MoreVertical20Regular,
} from '@fluentui/react-icons';
import { makeStyles } from '@fluentui/react-make-styles';
import { Card, CardFooter, CardHeader, CardPreview } from '../index';

const useStyles = makeStyles({
root: {
background: 'white',
padding: '6px',
width: '20px',
height: '20px',

'> img': {
width: '100%',
height: '100%',
},
},
});
const LogoBackground = (props: React.HTMLAttributes<HTMLElement>) => {
const styles = useStyles();

return <div className={styles.root}>{props.children}</div>;
};

export const ActionCard = () => (
<>
<Card style={{ minWidth: '368px' }} onClick={() => console.log('Test action')}>
<CardHeader
image={<img src="./avatar_elvia.svg" alt="Face of a person" />}
header={
<Body>
<b>Elvia Atkins</b> mentioned you
</Body>
}
description={<Caption>5h ago · About us - Overview</Caption>}
/>

<CardPreview
logo={
<LogoBackground>
<img src="./word_logo.svg" alt="Microsoft Word logo" />
</LogoBackground>
}
>
<img src="./doc_template.png" alt="Preview of a Word document " />
</CardPreview>

<CardFooter>
<Button icon={<ArrowReply16Regular />}>Reply</Button>
</CardFooter>
</Card>

<br />

<Card style={{ minWidth: '368px' }}>
<CardHeader
image={<img src="./avatar_mauricio.svg" alt="Face of a person" />}
header={
<Body>
<b>Mauricio August</b> <span style={{ color: 'gray' }}>+ 7 others edited</span>
</Body>
}
description={<Caption>Artificial Intelligence Deck</Caption>}
action={<DismissSquare20Regular />}
/>

<CardPreview
logo={
<LogoBackground>
<img src="./powerpoint_logo.svg" alt="Microsoft PowerPoint logo" />
</LogoBackground>
}
>
<img src="./ai_deck_template.png" alt="Preview of an artificial intelligence slide deck" />
</CardPreview>

<CardFooter action={<Button transparent icon={<MoreVertical20Regular />} />}>
<Button icon={<Open16Regular />}>View changes</Button>
</CardFooter>
</Card>
</>
);

export const GridviewCard = () => (
<Card
style={{
minWidth: '254px',
maxWidth: '368px',
}}
>
<CardPreview style={{ marginTop: '-12px' }}>
<img src="./sales_template.png" alt="Preview of a sales slide deck" />
</CardPreview>
<CardHeader
image={<img src="./powerpoint_logo.svg" alt="Microsoft PowerPoint logo" />}
header={
<Body>
<b>Sales Analysis</b>
</Body>
}
description={<Caption style={{ color: 'gray' }}>Elvia replied to a comment</Caption>}
action={<MoreHorizontal16Regular />}
/>
</Card>
);

export default {
title: 'Components/OfficeCard',
component: Card,
};
2 changes: 1 addition & 1 deletion packages/react-card/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useCardStyles } from './useCardStyles';
import type { CardProps } from './Card.types';

/**
* A card provides scaffolding for hosting actions and content for a single topic within a card sized object.
* Component to provide scaffolding for hosting actions and content for a single topic within a card sized object.
*/
export const Card = React.forwardRef<HTMLElement, CardProps>((props, ref) => {
const state = useCard(props, ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`Card renders a default state 1`] = `
<div>
<div
class=""
role="group"
>
Default Card
</div>
Expand Down
Loading

0 comments on commit e870763

Please sign in to comment.