Skip to content

Commit

Permalink
feat(ffe-cards-react): groupcard, fjernet nopadding og oppdatert utse…
Browse files Browse the repository at this point in the history
…ende

BREAKING CHANGE: dfd
  • Loading branch information
tuva-odegard committed Aug 19, 2024
1 parent d3af154 commit f30ee76
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/ffe-cards-react/src/GroupCard/GroupCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BgColor, BgColorDarkmode } from '../types';

export interface GroupCardProps
extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {
shadow?: boolean;
noShadow?: boolean;
/** The children of the GroupCard component */
children: React.ReactNode;
/** The background color of the whole groupcard element */
Expand All @@ -16,7 +16,7 @@ export interface GroupCardProps

function GroupCardWithForwardRef(
{
shadow,
noShadow,
className,
children,
bgColor,
Expand All @@ -30,7 +30,7 @@ function GroupCardWithForwardRef(
className={classNames(
'ffe-group-card',
{
'ffe-group-card--shadow': shadow,
'ffe-group-card--no-shadow': noShadow,
[`ffe-group-card--bg-${bgColor}`]: bgColor,
[`ffe-group-card--dm-bg-${bgDarkmodeColor}`]:
bgDarkmodeColor,
Expand Down
11 changes: 1 addition & 10 deletions packages/ffe-cards-react/src/GroupCard/GroupCardElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export type GroupCardElementProps<As extends ElementType = 'div'> = Omit<
ComponentAsPropParams<As>,
'children'
> & {
/** No padding on the element */
noPadding?: boolean;
/** Visible border between the elements*/
noSeparator?: boolean;
children:
Expand All @@ -21,19 +19,12 @@ function GroupCardElementWithForwardRef<As extends ElementType>(
props: GroupCardElementProps<As>,
ref: ForwardedRef<any>,
) {
const {
className,
noPadding,
noSeparator = false,
children,
...rest
} = props;
const { className, noSeparator = false, children, ...rest } = props;

return (
<WithCardAction
baseClassName="ffe-group-card__element"
className={classNames('ffe-group-card__element', className, {
'ffe-group-card__element--no-padding': noPadding,
'ffe-group-card__element--no-separator': noSeparator,
})}
{...(rest as Record<string, unknown>)}
Expand Down
38 changes: 38 additions & 0 deletions packages/ffe-cards-react/src/GroupCard/GroupCardFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { ElementType, ForwardedRef } from 'react';
import classNames from 'classnames';
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
import { CardRenderProps, ComponentAsPropParams } from '../types';
import { fixedForwardRef } from '../fixedForwardRef';

export type GroupCardFooterProps<As extends ElementType = 'div'> = Omit<
ComponentAsPropParams<As>,
'children'
> & {
children:
| React.ReactNode
| ((cardRenderProps: CardRenderProps) => React.ReactNode);
};

function GroupCardFooterWithForwardRef<As extends ElementType>(
props: GroupCardFooterProps<As>,
ref: ForwardedRef<any>,
) {
const { className, children, ...rest } = props;

return (
<WithCardAction
baseClassName="ffe-group-card__footer"
className={classNames('ffe-group-card__footer', className, {})}
{...(rest as Record<string, unknown>)}
ref={ref}
>
{({ CardAction }) =>
typeof children === 'function'
? children({ Text, Subtext, Title, CardName, CardAction })
: children
}
</WithCardAction>
);
}

export const GroupCardFooter = fixedForwardRef(GroupCardFooterWithForwardRef);
42 changes: 42 additions & 0 deletions packages/ffe-cards-react/src/GroupCard/GroupCardTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { ElementType, ForwardedRef } from 'react';
import classNames from 'classnames';
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
import { CardRenderProps, ComponentAsPropParams } from '../types';
import { fixedForwardRef } from '../fixedForwardRef';

export type GroupCardTitleProps<As extends ElementType = 'div'> = Omit<
ComponentAsPropParams<As>,
'children'
> & {
/** Visible border underneath title*/
noSeparator?: boolean;
children:
| React.ReactNode
| ((cardRenderProps: CardRenderProps) => React.ReactNode);
};

function GroupCardTitleWithForwardRef<As extends ElementType>(
props: GroupCardTitleProps<As>,
ref: ForwardedRef<any>,
) {
const { className, noSeparator = false, children, ...rest } = props;

return (
<WithCardAction
baseClassName="ffe-group-card__title"
className={classNames('ffe-group-card__title', className, {
'ffe-group-card__element--no-separator': noSeparator,
})}
{...(rest as Record<string, unknown>)}
ref={ref}
>
{({ CardAction }) =>
typeof children === 'function'
? children({ Text, Subtext, Title, CardName, CardAction })
: children
}
</WithCardAction>
);
}

export const GroupCardTitle = fixedForwardRef(GroupCardTitleWithForwardRef);
8 changes: 8 additions & 0 deletions packages/ffe-cards-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export {
GroupCardElement,
GroupCardElementProps,
} from './GroupCard/GroupCardElement';
export {
GroupCardTitle,
GroupCardTitleProps,
} from './GroupCard/GroupCardTitle';
export {
GroupCardFooter,
GroupCardFooterProps,
} from './GroupCard/GroupCardFooter';
export {
IllustrationCard,
IllustrationCardProps,
Expand Down

0 comments on commit f30ee76

Please sign in to comment.