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

Fix: Implement Custom Style Hook for Card component #33912

Merged
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
consolidated useCardStyles into CardDefault story
  • Loading branch information
terynkum committed Feb 26, 2025
commit a87d46cc2d90c0d113a796a25f19c1636040c487

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
import * as React from 'react';

import { makeStyles, Body1, Caption1, Button } from '@fluentui/react-components';
import {
makeStyles,
Body1,
Caption1,
Button,
mergeClasses,
tokens,
FluentProvider,
Card,
CardFooter,
CardHeader,
CardPreview,
} from '@fluentui/react-components';
import { ArrowReplyRegular, ShareRegular } from '@fluentui/react-icons';
import { Card, CardFooter, CardHeader, CardPreview } from '@fluentui/react-components';
import type { CardState, FluentProviderCustomStyleHooks } from '@fluentui/react-components';

const useCardStyle = makeStyles({
root: {
backgroundColor: tokens.colorNeutralBackground3,
width: '620px',
maxWidth: '100%',
margin: 'auto',
},
});

export const useCardStyles = (state: unknown) => {
const cardStyles = useCardStyle();
const componentState = state as CardState;
componentState.root.className = mergeClasses(componentState.root.className, cardStyles.root);
};

export const customStyleHooks: FluentProviderCustomStyleHooks = {
useCardStyles_unstable: useCardStyles,
};

const resolveAsset = (asset: string) => {
const ASSET_URL =
@@ -23,25 +54,27 @@ export const Default = () => {
const styles = useStyles();

return (
<Card className={styles.card}>
<CardHeader
image={<img src={resolveAsset('avatar_elvia.svg')} alt="Elvia Atkins avatar picture" />}
header={
<Body1>
<b>Elvia Atkins</b> mentioned you
</Body1>
}
description={<Caption1>5h ago · About us - Overview</Caption1>}
/>

<CardPreview logo={<img src={resolveAsset('docx.png')} alt="Microsoft Word document" />}>
<img src={resolveAsset('doc_template.png')} alt="Preview of a Word document: About Us - Overview" />
</CardPreview>

<CardFooter>
<Button icon={<ArrowReplyRegular fontSize={16} />}>Reply</Button>
<Button icon={<ShareRegular fontSize={16} />}>Share</Button>
</CardFooter>
</Card>
<FluentProvider customStyleHooks_unstable={customStyleHooks}>
<Card className={styles.card}>
<CardHeader
image={<img src={resolveAsset('avatar_elvia.svg')} alt="Elvia Atkins avatar picture" />}
header={
<Body1>
<b>Elvia Atkins</b> mentioned you
</Body1>
}
description={<Caption1>5h ago · About us - Overview</Caption1>}
/>

<CardPreview logo={<img src={resolveAsset('docx.png')} alt="Microsoft Word document" />}>
<img src={resolveAsset('doc_template.png')} alt="Preview of a Word document: About Us - Overview" />
</CardPreview>

<CardFooter>
<Button icon={<ArrowReplyRegular fontSize={16} />}>Reply</Button>
<Button icon={<ShareRegular fontSize={16} />}>Share</Button>
</CardFooter>
</Card>
</FluentProvider>
);
};
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ export { SelectableIndicator } from './CardSelectableIndicator.stories';
export { WithAction } from './CardAction.stories';
export { FocusMode } from './CardFocusMode.stories';
export { Templates } from './CardTemplates.stories';
export { CardCustomStyles } from './CardCustomStyles.stories';

export default {
title: 'Components/Card/Card',
Loading
Oops, something went wrong.