Skip to content

Commit

Permalink
feat(IconCard): Legg til prop for å plassere ikon på høyre side
Browse files Browse the repository at this point in the history
  • Loading branch information
abhustoft committed Aug 16, 2024
1 parent 09552a4 commit ce356be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
22 changes: 12 additions & 10 deletions component-overview/examples/cards/IconCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { IconCard } from '@sb1/ffe-cards-react';
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iNDgiPjxwYXRoIGQ9Ik0yNDMuMDc4LTE0MC4wMDFxLTIwLjIzMSAwLTM3LjgxNy0xMy4zNy0xNy41ODYtMTMuMzY5LTIzLjEwNi0zMi43MDctMjUtODcuNTM5LTQwLjk2NS0xNDguMjY2LTE1Ljk2Ni02MC43MjctMjUuMDE5LTEwNC42ODItOS4wNTItNDMuOTU1LTEyLjYxMS03Ni43OTEtMy41NTktMzIuODM2LTMuNTU5LTY0LjM2MyAwLTgzLjM1OCA1OC4yMzEtMTQxLjU4OCA1OC4yMy01OC4yMzEgMTQxLjc2OC01OC4yMzFoMjEwLjAwMXEyNy0zNiA2Ni01OCAzOC45OTktMjIgODMuOTk5LTIyIDE2LjUzOCAwIDI4LjI2OCAxMS43MzEgMTEuNzMxIDExLjczIDExLjczMSAyOC4yNjggMCA0LjA3Ny0xLjExNiA3Ljk2MS0xLjExNSAzLjg4NS0yLjM0NiA3LjczMS00LjM4NSAxMS43NjktOC40NjEgMjUuNDYyLTQuMDc3IDEzLjY5Mi03LjYxNiAzNC43N2wxMDQuMDc4IDEwNC4wNzdoNDYuNjE0cTEyLjM1NiAwIDIwLjYwMSA4LjI0NiA4LjI0NiA4LjI0NSA4LjI0NiAyMC42MDF2MTk0LjMwNXEwIDkuODc4LTUuMjQ2IDE3Lj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wcTAtMTQuNjkyLTEwLjM0Ni0yNS4wMzhUNjQwLTU5NS4zODRxLTE0LjY5MiAwLTI1LjAzOCAxMC4zNDZUNjA0LjYxNi01NjBxMCAxNC42OTIgMTAuMzQ2IDI1LjAzOFQ2NDAtNTI0LjYxNlptLTE0Mi42OTItMTAwcTkuNjYzIDAgMTYuMTc4LTYuNTY2UTUyMC02MzcuNzQ5IDUyMC02NDcuNDlxMC05Ljc0LTYuNTE0LTE2LjEyNS02LjUxNS02LjM4NC0xNi4xNzgtNi4zODRIMzQyLjY5MnEtOS42NjMgMC0xNi4xNzggNi41NjZRMzIwLTY1Ni44NjYgMzIwLTY0Ny4xMjVxMCA5Ljc0IDYuNTE0IDE2LjEyNSA2LjUxNSA2LjM4NCAxNi4xNzggNi4zODRoMTU0LjYxNlpNNDgwLTUwMC44NDZaIi8+PC9zdmc+';

return (
<IconCard icon={<Icon fileUrl={savingsIconXlarge} size="xl" />}>
{({ CardName, Title, Subtext, Text }) => (
<>
<CardName>Kortnavn</CardName>
<Title>Tittel</Title>
<Subtext>En liten undertekst</Subtext>
<Text>Her kan man ha tekst</Text>
</>
)}
</IconCard>
<>
<IconCard icon={<Icon fileUrl={savingsIconXlarge} size="xl" />}>
{({ CardName, Title, Subtext, Text }) => (
<>
<CardName>Kortnavn</CardName>
<Title>Tittel</Title>
<Subtext>En liten undertekst</Subtext>
<Text>Her kan man ha tekst</Text>
</>
)}
</IconCard>
</>
);
};
15 changes: 15 additions & 0 deletions packages/ffe-cards-react/src/IconCard/IconCard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ describe('IconCard', () => {
).toBeTruthy();
});

it('should add modifying classes when modifier iconOnRight is given', () => {
render(
<IconCard
data-testid={TEST_ID}
iconOnRight={true}
icon={<Icon fileUrl={savingsIconXlarge} size="xl" />}
>
{children}
</IconCard>,
);
const card = screen.getByTestId(TEST_ID);
expect(card.classList.contains('ffe-icon-card')).toBeTruthy();
expect(card.classList.contains('ffe-icon-card--icon-right')).toBeTruthy();
});

it('should render children as a function', () => {
render(
<IconCard
Expand Down
4 changes: 3 additions & 1 deletion packages/ffe-cards-react/src/IconCard/IconCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type IconCardProps<As extends ElementType = 'div'> = Omit<
icon: ReactElement;
/** Smaller icon and less space */
condensed?: boolean;
iconOnRight?: boolean;
children:
| React.ReactNode
| ((cardRenderProps: CardRenderProps) => React.ReactNode);
Expand All @@ -21,13 +22,14 @@ function IconCardWithForwardRef<As extends ElementType>(
props: IconCardProps<As>,
ref: ForwardedRef<any>,
) {
const { className, condensed, icon, children, ...rest } = props;
const { className, condensed, icon, children, iconOnRight, ...rest } = props;
return (
<WithCardAction
baseClassName="ffe-icon-card"
className={classNames(
'ffe-icon-card',
{ 'ffe-icon-card--condensed': condensed },
{ 'ffe-icon-card--icon-right': iconOnRight },
className,
)}
{...(rest as Record<string, unknown>)}
Expand Down
4 changes: 4 additions & 0 deletions packages/ffe-cards/less/icon-card.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
margin: 0 var(--ffe-spacing-sm) 0 0;
}
}

.ffe-icon-card--icon-right {
flex-direction: row-reverse;
}

0 comments on commit ce356be

Please sign in to comment.