From a53825e10a703478a12cd15aa8bcc4bb664795e3 Mon Sep 17 00:00:00 2001 From: Iveta Date: Wed, 27 Mar 2024 11:29:07 -0400 Subject: [PATCH] CopyText updated (#230) * CopyText updated * Fix CSS var * Bump SDS to v1.1.3 --- @stellar/design-system-website/package.json | 2 +- .../src/components/ComponentProps/index.tsx | 20 ++++-- .../src/components/ComponentProps/styles.css | 8 +++ @stellar/design-system/package.json | 2 +- .../src/components/CopyText/index.tsx | 69 +++++++++++++++++-- .../src/components/CopyText/styles.scss | 18 ++++- 6 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 @stellar/design-system-website/src/components/ComponentProps/styles.css diff --git a/@stellar/design-system-website/package.json b/@stellar/design-system-website/package.json index 03e9d233..140805c5 100644 --- a/@stellar/design-system-website/package.json +++ b/@stellar/design-system-website/package.json @@ -23,7 +23,7 @@ "@docusaurus/remark-plugin-npm2yarn": "^3.1.0", "@docusaurus/theme-live-codeblock": "^3.1.0", "@mdx-js/react": "^3.0.0", - "@stellar/design-system": "^1.1.2", + "@stellar/design-system": "^1.1.3", "clsx": "^2.1.0", "prism-react-renderer": "^2.3.1", "react": "^18.2.0", diff --git a/@stellar/design-system-website/src/components/ComponentProps/index.tsx b/@stellar/design-system-website/src/components/ComponentProps/index.tsx index 9120bbe6..0c434a15 100644 --- a/@stellar/design-system-website/src/components/ComponentProps/index.tsx +++ b/@stellar/design-system-website/src/components/ComponentProps/index.tsx @@ -4,13 +4,15 @@ import { Element } from "@site/src/components/Element"; import { ParseSummary } from "@site/src/components/ParseSummary"; import { ElementPropType } from "@site/src/components/ElementPropType"; +import "./styles.css"; + export const ComponentProps = ({ componentName, relatedType, }: { componentName: string; // To associate custom types that are used in the component. For example, - // AssetIconSource in AssetIcon. + // AssetSource in Asset. relatedType?: string[]; }) => { const component = SdsDocs?.children?.find( @@ -28,6 +30,16 @@ export const ComponentProps = ({ const PropRow = ({ p }: { p: any }) => { const defaultVal = p.comment?.blockTags?.[0]?.content?.[0]; + // Don't show row that is optional and undefined + // (used in discriminated union types) + if ( + p?.flags?.isOptional && + p.type.type === "intrinsic" && + p.type.name === "undefined" + ) { + return null; + } + return ( @@ -54,14 +66,14 @@ export const ComponentProps = ({ ); }; - const props = component.children.map((p) => ); + const props = component?.children?.map((p) => ); const relatedTypeProps = relatedTypes?.map((t) => { const props = t.children || t?.type?.declaration?.children; return ( - + {t.name} @@ -75,7 +87,7 @@ export const ComponentProps = ({ return (
- +
diff --git a/@stellar/design-system-website/src/components/ComponentProps/styles.css b/@stellar/design-system-website/src/components/ComponentProps/styles.css new file mode 100644 index 00000000..e3ad641c --- /dev/null +++ b/@stellar/design-system-website/src/components/ComponentProps/styles.css @@ -0,0 +1,8 @@ +tr.PropsTable__subtitle { + font-weight: 600; +} + +tr.PropsTable__subtitle td { + border-top-width: 2px; + border-bottom-width: 2px; +} diff --git a/@stellar/design-system/package.json b/@stellar/design-system/package.json index 5f1f73db..a3d86c4d 100755 --- a/@stellar/design-system/package.json +++ b/@stellar/design-system/package.json @@ -1,6 +1,6 @@ { "name": "@stellar/design-system", - "version": "1.1.2", + "version": "1.1.3", "author": "Stellar Development Foundation ", "description": "Components for Stellar Development Foundation’s design system", "license": "Apache-2.0", diff --git a/@stellar/design-system/src/components/CopyText/index.tsx b/@stellar/design-system/src/components/CopyText/index.tsx index 9a0b69e4..39824715 100644 --- a/@stellar/design-system/src/components/CopyText/index.tsx +++ b/@stellar/design-system/src/components/CopyText/index.tsx @@ -1,13 +1,13 @@ -import React, { useState } from "react"; +import React, { cloneElement, useState } from "react"; import CopyToClipboard from "react-copy-to-clipboard"; import { Tooltip } from "../Tooltip"; import "./styles.scss"; /** */ -export interface CopyTextProps { +export type CopyTextBaseProps = { /** Text to copy */ textToCopy: string; - /** Label/text to display when copy action is done @defaultValue Copied */ + /** Label/text to display when copy action is done @defaultValue `Copied` */ doneLabel?: string; /** Position of the tooltip @defaultValue `bottom` */ tooltipPlacement?: @@ -23,17 +23,34 @@ export interface CopyTextProps { | "bottom-end" | "left-start" | "left-end"; - /** Title text to show on hover @defaultValue Copy */ + /** Title text to show on hover @defaultValue `Copy` */ title?: string; +}; + +export type CopyTextEllipsisProps = { + /** Component display variant. `ellipsis` parent must have position relative. */ + variant?: "ellipsis"; + /** Copy click element */ + children: string; +}; + +export type CopyTextVariantProps = { + /** Component display variant. `headless` parent must have position relative. @defaultValue `inline` */ + variant?: "inline" | "headless"; /** Copy click element */ children: React.ReactElement; -} +}; + +/** */ +export type CopyTextProps = (CopyTextVariantProps | CopyTextEllipsisProps) & + CopyTextBaseProps; /** - * Use the `CopyText` component to copy a string. Done action label can be displayed in a tooltip, by default it will replace the component’s label inline. We’re using [react-copy-to-clipboard](https://github.com/nkbt/react-copy-to-clipboard) to handle the copy part. + * Use the `CopyText` component to copy a string. We’re using [react-copy-to-clipboard](https://github.com/nkbt/react-copy-to-clipboard) to handle the copy part. */ export const CopyText: React.FC = ({ textToCopy, + variant = "inline", doneLabel = "Copied", tooltipPlacement = "bottom", title = "Copy", @@ -54,8 +71,46 @@ export const CopyText: React.FC = ({ }, 1000); }; + if (variant === "headless") { + return ( + + {cloneElement(children as React.ReactElement, { + title, + })} + + } + placement={tooltipPlacement} + > + {doneLabel} + + ); + } + + if (variant === "ellipsis") { + return ( +
+ +
+ {children} +
+ + } + placement={tooltipPlacement} + > + {doneLabel} +
+
+ ); + } + return ( -
+
Prop