diff --git a/@stellar/design-system-website/docs/components/elements/asset-icon.mdx b/@stellar/design-system-website/docs/components/elements/asset-icon.mdx new file mode 100644 index 00000000..5c58c619 --- /dev/null +++ b/@stellar/design-system-website/docs/components/elements/asset-icon.mdx @@ -0,0 +1,27 @@ +--- +slug: /asset-icon +--- + +# Asset icon + + + +## Example + +```tsx live + + + +``` + +## Props + + diff --git a/@stellar/design-system-website/src/componentPreview/assetIconPreview.tsx b/@stellar/design-system-website/src/componentPreview/assetIconPreview.tsx new file mode 100644 index 00000000..ce47e8a3 --- /dev/null +++ b/@stellar/design-system-website/src/componentPreview/assetIconPreview.tsx @@ -0,0 +1,31 @@ +import { ComponentPreview } from "@site/src/components/PreviewBlock"; + +export const assetIconPreview: ComponentPreview = { + options: [ + { + type: "select", + prop: "source", + customValue: [ + { + altText: "XLM", + image: "https://cryptologos.cc/logos/stellar-xlm-logo.svg?v=024", + imageSize: "80%", + }, + { + altText: "USDC", + image: "https://cryptologos.cc/logos/usd-coin-usdc-logo.svg?v=024", + }, + ], + options: [ + { + value: "", + label: "Single", + }, + { + value: "pair", + label: "Pair", + }, + ], + }, + ], +}; diff --git a/@stellar/design-system-website/src/components/ComponentProps/index.tsx b/@stellar/design-system-website/src/components/ComponentProps/index.tsx index d0864903..6acea43b 100644 --- a/@stellar/design-system-website/src/components/ComponentProps/index.tsx +++ b/@stellar/design-system-website/src/components/ComponentProps/index.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { Fragment } from "react"; import SdsDocs from "@stellar/design-system/docs/components.json"; import { Element } from "@site/src/components/Element"; import { ParseSummary } from "@site/src/components/ParseSummary"; @@ -6,8 +6,12 @@ import { ElementPropType } from "@site/src/components/ElementPropType"; export const ComponentProps = ({ componentName, + relatedType, }: { componentName: string; + // To associate custom types that are used in the component. For example, + // AssetIconSource in AssetIcon. + relatedType?: string[]; }) => { const component = SdsDocs?.children?.find( (c) => c.name === `${componentName}Props` && c.variant === "declaration", @@ -17,7 +21,11 @@ export const ComponentProps = ({ throw Error(`Component "${componentName}" props not found.`); } - const props = component.children.map((p) => { + const relatedTypes = relatedType?.map((t) => + SdsDocs?.children?.find((c) => c.name === t && c.variant === "declaration"), + ); + + const PropRow = ({ p }: { p: any }) => { const defaultVal = p.comment?.blockTags?.[0]?.content?.[0]; return ( @@ -44,6 +52,23 @@ export const ComponentProps = ({ ); + }; + + const props = component.children.map((p) => ); + + const relatedTypeProps = relatedTypes?.map((t) => { + return ( + + + + {t.name} + + + {t?.type?.declaration?.children?.map((t) => ( + + ))} + + ); }); return ( @@ -58,8 +83,12 @@ export const ComponentProps = ({ Description - {props} + + {props} + {relatedTypeProps} + + {component.comment?.summary ? (

diff --git a/@stellar/design-system-website/src/components/ElementPropType.tsx b/@stellar/design-system-website/src/components/ElementPropType.tsx index 07c1d2e3..959504b4 100644 --- a/@stellar/design-system-website/src/components/ElementPropType.tsx +++ b/@stellar/design-system-website/src/components/ElementPropType.tsx @@ -12,6 +12,8 @@ export const ElementPropType = ({ type }: { type: any }) => { // TODO: we currently have only this type for functions, but it would be // nice to parse it properly return {`() => void`}; + case "array": + return {`${type?.elementType?.name || ""}[]`}; case "intrinsic": case "reference": return {type.name}; diff --git a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx index e08f259f..1872f134 100644 --- a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx +++ b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx @@ -6,6 +6,7 @@ import "./styles.css"; // ============================================================================= // Preview imports // ============================================================================= +import { assetIconPreview } from "@site/src/componentPreview/assetIconPreview"; import { avatarPreview } from "@site/src/componentPreview/avatarPreview"; import { badgePreview } from "@site/src/componentPreview/badgePreview"; import { bannerPreview } from "@site/src/componentPreview/bannerPreview"; @@ -23,6 +24,7 @@ import { titlePreview } from "@site/src/componentPreview/titlePreview"; // Component previews // ============================================================================= const previews: { [key: string]: ComponentPreview } = { + AssetIcon: assetIconPreview, Avatar: avatarPreview, Badge: badgePreview, Banner: bannerPreview, diff --git a/@stellar/design-system/src/components/AssetIcon/index.tsx b/@stellar/design-system/src/components/AssetIcon/index.tsx index 139cba17..f3f598ec 100644 --- a/@stellar/design-system/src/components/AssetIcon/index.tsx +++ b/@stellar/design-system/src/components/AssetIcon/index.tsx @@ -1,17 +1,28 @@ import "./styles.scss"; -type AssetIconSource = { +/** */ +export type AssetIconSource = { + /** Image URL */ image: string; + /** Image alt text */ altText: string; + /** Custom size of the image inside the circle */ imageSize?: string; + /** Custom background color */ backgroundColor?: string; }; -type AssetIconProps = { +/** */ +export interface AssetIconProps { + /** Asset source data */ source: AssetIconSource[]; + /** Asset border color */ borderColor?: string; -}; +} +/** + * Asset image displayed in a circle from a URL source. The component accepts multiple sources to show currency pair, for example. + */ export const AssetIcon: React.FC = ({ source, borderColor,