-
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
11553ba
commit c9dfdf5
Showing
198 changed files
with
667 additions
and
2,786 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
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.
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, | ||
}, | ||
}); | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/components/icon/src/utils/generateIconComponent.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,49 @@ | ||
import React, { type ReactElement } from 'react'; | ||
import { Icon, type IconProps } from '../Icon'; | ||
|
||
export type GeneratedIconProps = Omit< | ||
IconProps, | ||
'as' | 'children' | 'name' | 'viewBox' | ||
> & { | ||
children?: never; | ||
}; | ||
|
||
type GenerateIconComponentParameters = { | ||
/** | ||
* Icon name is used as the generated icon's component display name | ||
*/ | ||
name?: string; | ||
/** | ||
* The SVG path(s) to render in the icon wrapper | ||
*/ | ||
path: ReactElement; | ||
/** | ||
* A collection of default props to set on the generated icon | ||
*/ | ||
props?: GeneratedIconProps; | ||
/** | ||
* Custom SVG viewBox attribute to use for the generated icon | ||
*/ | ||
viewBox?: IconProps['viewBox']; | ||
}; | ||
|
||
export function generateIconComponent({ | ||
name, | ||
path, | ||
props: defaultProps, | ||
viewBox, | ||
}: GenerateIconComponentParameters) { | ||
const Component = function (props: IconProps) { | ||
return ( | ||
<Icon viewBox={viewBox} {...defaultProps} {...props}> | ||
{path} | ||
</Icon> | ||
); | ||
}; | ||
|
||
if (name) { | ||
Component.displayName = name; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './generateComponentWithVariants'; | ||
export * from './generateForma36Icon'; | ||
export * from './generateIconComponent'; |
Oops, something went wrong.