-
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.
- Loading branch information
1 parent
d60e32e
commit 97288af
Showing
196 changed files
with
906 additions
and
2,959 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { generateIcon } from './generateIcon'; | ||
export type { GeneratedIconProps } from './generateIcon'; | ||
export { Icon } from './Icon'; | ||
export type { IconProps, IconComponent, IconSize, IconVariant } from './Icon'; | ||
export * from './utils'; | ||
export { Icon, type IconProps } from './Icon'; | ||
export * from './types'; |
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,11 @@ | ||
import { type ComponentType, type ExoticComponent } from 'react'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type IconComponent = ExoticComponent<any> | ComponentType<any>; | ||
|
||
export type IconSize = 'medium' | 'small' | 'tiny'; | ||
|
||
export enum IconVariant { | ||
Active = 'active', | ||
Default = 'default', | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/components/icon/src/utils/generateComponentWithVariants.ts
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,18 @@ | ||
import { IconVariant } from '../types'; | ||
import type { GeneratedIconProps } from './generateIconComponent'; | ||
|
||
export function generateComponentWithVariants({ | ||
variants, | ||
}: { | ||
variants: Record<IconVariant, React.FunctionComponent<GeneratedIconProps>>; | ||
}) { | ||
const Component = function (props: GeneratedIconProps) { | ||
if (props.isActive) { | ||
return variants[IconVariant.Active](props); | ||
} | ||
|
||
return variants[IconVariant.Default](props); | ||
}; | ||
|
||
return Component; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/components/icon/src/utils/generateForma36Icon.tsx
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,18 @@ | ||
import React from 'react'; | ||
import { IconVariant } from '../types'; | ||
import { generateComponentWithVariants } from './generateComponentWithVariants'; | ||
import { wrapPhosphorIcon } from './wrapPhosphorIcon'; | ||
|
||
/** | ||
* Helper function to generate a Forma 36 icon component from a Phosphor icon component | ||
*/ | ||
export function generateForma36Icon(PhosphorIcon) { | ||
const Icon = wrapPhosphorIcon(PhosphorIcon); | ||
|
||
return generateComponentWithVariants({ | ||
variants: { | ||
[IconVariant.Active]: (props) => <Icon {...props} weight="fill" />, | ||
[IconVariant.Default]: Icon, | ||
}, | ||
}); | ||
} |
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,3 @@ | ||
export * from './generateComponentWithVariants'; | ||
export * from './generateForma36Icon'; | ||
export * from './generateIconComponent'; |
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 from 'react'; | ||
import type { Icon as PhosphorIcon } from '@phosphor-icons/react'; | ||
import tokens from '@contentful/f36-tokens'; | ||
import { Icon, sizes } from '../Icon'; | ||
import type { GeneratedIconProps } from './generateIconComponent'; | ||
|
||
// Unfortunately we have to pass props directly to the Phosphor icon | ||
export function wrapPhosphorIcon(PhosphorIcon: PhosphorIcon) { | ||
const Component = ({ | ||
isActive = false, | ||
color = isActive ? tokens.blue500 : tokens.gray900, | ||
size = 'medium', | ||
...props | ||
}: GeneratedIconProps & { weight?: 'fill' }) => { | ||
return ( | ||
<Icon | ||
{...props} | ||
as={() => <PhosphorIcon {...props} color={color} size={sizes[size]} />} | ||
/> | ||
); | ||
}; | ||
|
||
return Component; | ||
} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.