-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ffe-cards-react): rewrite in ts
BREAKING CHANGE: different props element -> as
- Loading branch information
Peter Hellstrand
committed
May 6, 2024
1 parent
25ce15b
commit f13e402
Showing
36 changed files
with
518 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
"url": "ssh://[email protected]:SpareBank1/designsystem.git" | ||
}, | ||
"scripts": { | ||
"build": "ffe-buildtool babel", | ||
"watch": "ffe-buildtool babel-watch", | ||
"build": "ffe-buildtool tsc", | ||
"watch": "ffe-buildtool tsc-watch", | ||
"lint": "eslint src", | ||
"lint:fix": "eslint src --fix", | ||
"test": "ffe-buildtool jest", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { ElementType, ForwardedRef } from 'react'; | ||
import { fixedForwardRef } from './fixedForwardRef'; | ||
import { ComponentAsPropParams } from './types'; | ||
import classNames from 'classnames'; | ||
|
||
export type CardBaseProps<As extends ElementType = 'a'> = | ||
ComponentAsPropParams<As>; | ||
|
||
function CardBaseWithForwardRef<As extends ElementType>( | ||
props: CardBaseProps<As>, | ||
ref: ForwardedRef<any>, | ||
) { | ||
const { as: Comp = 'a', className, ...rest } = props; | ||
|
||
return ( | ||
<Comp | ||
className={classNames('ffe-card-base', className)} | ||
{...rest} | ||
ref={ref} | ||
/> | ||
); | ||
} | ||
|
||
export const CardBase = fixedForwardRef(CardBaseWithForwardRef); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { ElementType, ForwardedRef, ReactElement } from 'react'; | ||
import { fixedForwardRef } from '../fixedForwardRef'; | ||
import { ComponentAsPropParams, CardRenderProps } from '../types'; | ||
import classNames from 'classnames'; | ||
import { Text, Subtext, Title, CardName } from '../components'; | ||
|
||
export type IconCardProps<As extends ElementType = 'a'> = Omit< | ||
ComponentAsPropParams<As>, | ||
'children' | ||
> & { | ||
/** Element of icon */ | ||
icon: ReactElement; | ||
/** Smaller icon and less space */ | ||
condensed?: boolean; | ||
children: | ||
| React.ReactNode | ||
| ((cardRenderProps: CardRenderProps) => React.ReactNode); | ||
}; | ||
|
||
function IconCardWithForwardRef<As extends ElementType>( | ||
props: IconCardProps<As>, | ||
ref: ForwardedRef<any>, | ||
) { | ||
const { | ||
as: Comp = 'a', | ||
className, | ||
condensed, | ||
icon, | ||
children, | ||
...rest | ||
} = props; | ||
|
||
return ( | ||
<Comp | ||
className={classNames( | ||
'ffe-icon-card', | ||
{ 'ffe-icon-card--condensed': condensed }, | ||
className, | ||
)} | ||
{...rest} | ||
ref={ref} | ||
> | ||
{React.cloneElement(icon, { | ||
...icon.props, | ||
className: classNames( | ||
'ffe-icon-card__icon', | ||
icon.props.className, | ||
), | ||
})} | ||
<div className="ffe-icon-card__body"> | ||
{typeof children === 'function' | ||
? children({ Text, Subtext, Title, CardName }) | ||
: children} | ||
</div> | ||
</Comp> | ||
); | ||
} | ||
|
||
export const IconCard = fixedForwardRef(IconCardWithForwardRef); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.