From f30d3ee5cd39e6946cc51464e4d9a3126743cbd1 Mon Sep 17 00:00:00 2001 From: Sean Hughes Date: Thu, 19 Dec 2024 14:30:25 -0500 Subject: [PATCH 1/6] Simple components for common HTML usage --- .changeset/itchy-donkeys-fail.md | 5 +++ .../src/lib/unsorted/ui/Card.stories.svelte | 24 +++++++++++++ .../src/lib/unsorted/ui/Card.svelte | 14 ++++++++ .../src/lib/unsorted/ui/Embed.stories.svelte | 17 +++++++++ .../src/lib/unsorted/ui/Embed.svelte | 35 +++++++++++++++++++ .../lib/unsorted/ui/Footnote.stories.svelte | 35 +++++++++++++++++++ .../src/lib/unsorted/ui/Footnote.svelte | 18 ++++++++++ .../src/lib/unsorted/ui/Image.stories.svelte | 20 +++++++++++ .../src/lib/unsorted/ui/Image.svelte | 30 ++++++++++++++++ .../src/lib/unsorted/ui/Link.stories.svelte | 17 +++++++++ .../src/lib/unsorted/ui/Link.svelte | 20 +++++++++++ .../src/lib/unsorted/ui/index.js | 5 +++ 12 files changed, 240 insertions(+) create mode 100644 .changeset/itchy-donkeys-fail.md create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Card.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Embed.stories.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Footnote.stories.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Footnote.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Image.stories.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Image.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Link.stories.svelte create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Link.svelte diff --git a/.changeset/itchy-donkeys-fail.md b/.changeset/itchy-donkeys-fail.md new file mode 100644 index 0000000000..f3c6895bb7 --- /dev/null +++ b/.changeset/itchy-donkeys-fail.md @@ -0,0 +1,5 @@ +--- +'@evidence-dev/core-components': patch +--- + +Add simple wrapper components for common HTML usgae diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte new file mode 100644 index 0000000000..02b2ef5075 --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte @@ -0,0 +1,24 @@ + + + + + + {@const data = Query.create(`select * from numeric_series`, query)} + + + + diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Card.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Card.svelte new file mode 100644 index 0000000000..3e47d9a943 --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Card.svelte @@ -0,0 +1,14 @@ + + + + +
+ +
diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Embed.stories.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Embed.stories.svelte new file mode 100644 index 0000000000..65feb8e84f --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Embed.stories.svelte @@ -0,0 +1,17 @@ + + + + + + + diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte new file mode 100644 index 0000000000..59d2449295 --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte @@ -0,0 +1,35 @@ + + + + +
+ +
diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Footnote.stories.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Footnote.stories.svelte new file mode 100644 index 0000000000..fc0aaebceb --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Footnote.stories.svelte @@ -0,0 +1,35 @@ + + + + + + {@const data = Query.create(`select * from numeric_series`, query)} + + The data for this report was sourced from the World Bank World Development Indicators dataset. + + + The data for this report was sourced from the World Bank World Development Indicators dataset. + + + The data for this report was sourced from the World Bank World Development Indicators dataset. + + + + The data for this report was sourced from the World Bank World Development Indicators dataset. + + + diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Footnote.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Footnote.svelte new file mode 100644 index 0000000000..4b19368d77 --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Footnote.svelte @@ -0,0 +1,18 @@ + + + + +
+
+ + {id} + +
+ +
+
+
diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Image.stories.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Image.stories.svelte new file mode 100644 index 0000000000..36465aef92 --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Image.stories.svelte @@ -0,0 +1,20 @@ + + + + + + + diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte new file mode 100644 index 0000000000..f66e004f1c --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte @@ -0,0 +1,30 @@ + + + + +
+ {description} +
diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Link.stories.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Link.stories.svelte new file mode 100644 index 0000000000..8e5814606c --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Link.stories.svelte @@ -0,0 +1,17 @@ + + + + + + + diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Link.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Link.svelte new file mode 100644 index 0000000000..765286c885 --- /dev/null +++ b/packages/ui/core-components/src/lib/unsorted/ui/Link.svelte @@ -0,0 +1,20 @@ + + + + + + {label} + diff --git a/packages/ui/core-components/src/lib/unsorted/ui/index.js b/packages/ui/core-components/src/lib/unsorted/ui/index.js index a7aa723ea0..e87f708b66 100644 --- a/packages/ui/core-components/src/lib/unsorted/ui/index.js +++ b/packages/ui/core-components/src/lib/unsorted/ui/index.js @@ -1,13 +1,18 @@ export { default as LinkButton } from './LinkButton.svelte'; export { default as BigLink } from './BigLink.svelte'; +export { default as Card } from './Card.svelte'; export { default as ChevronToggle } from './ChevronToggle.svelte'; export { default as CodeBlock } from './CodeBlock.svelte'; export { default as Details } from './Details.svelte'; export { default as DownloadData } from './DownloadData.svelte'; export { default as EmailSignup } from './EmailSignup.svelte'; +export { default as Embed } from './Embed.svelte'; +export { default as Footnote } from './Footnote.svelte'; export { default as Group } from './Group.svelte'; +export { default as Image } from './Image.svelte'; export { default as LastRefreshed } from './LastRefreshed.svelte'; export { default as LineBreak } from './LineBreak.svelte'; +export { default as Link } from './Link.svelte'; export { default as LoadingIndicator } from './LoadingIndicator.svelte'; export { default as Modal } from './Modal.svelte'; export { default as PageBreak } from './PageBreak.svelte'; From 356d13024438849dd5adccb8920cf6fc85bb3c97 Mon Sep 17 00:00:00 2001 From: Sean Hughes Date: Fri, 20 Dec 2024 08:34:48 -0500 Subject: [PATCH 2/6] add and use utils --- .../src/lib/unsorted/ui/Image.svelte | 8 ++------ .../src/lib/unsorted/ui/Link.svelte | 4 +++- packages/ui/core-components/src/lib/utils.js | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte index f66e004f1c..cb5f883bf0 100644 --- a/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte +++ b/packages/ui/core-components/src/lib/unsorted/ui/Image.svelte @@ -3,17 +3,13 @@ diff --git a/packages/ui/core-components/src/lib/utils.js b/packages/ui/core-components/src/lib/utils.js index ee7c7a6f4c..9b99ffc270 100644 --- a/packages/ui/core-components/src/lib/utils.js +++ b/packages/ui/core-components/src/lib/utils.js @@ -81,3 +81,18 @@ export const toBoolean = (value) => { } return Boolean(value); }; + +/** + * Processes a dimension value to ensure it is in a valid CSS format. + * + * If the input is a plain number (e.g., "10"), "px" is appended to it. + * If the input is already in a valid format (e.g., "10px", "5em", "auto"), it is returned as-is. + * If the input is falsy, an empty string is returned. + * + * @param {string | number | undefined} dimension - The dimension value to process. + * @returns {string} The processed dimension with "px" appended if it's a number, or the original value. + */ +export const processDimension = (dimension) => { + if (!dimension) return ''; // No dimension provided + return /^\d+$/.test(dimension) ? `${dimension}px` : dimension; // Add 'px' if it's a number +}; From a643f75272b04667cc70950372a4bab1f6edfc75 Mon Sep 17 00:00:00 2001 From: Sean Hughes Date: Tue, 31 Dec 2024 12:23:26 -0500 Subject: [PATCH 3/6] remove card and add class props --- .../src/lib/unsorted/ui/Card.stories.svelte | 24 ------------------- .../src/lib/unsorted/ui/Card.svelte | 14 ----------- .../src/lib/unsorted/ui/Embed.svelte | 14 ++++++++--- .../src/lib/unsorted/ui/Footnote.svelte | 18 -------------- .../src/lib/unsorted/ui/Image.svelte | 15 ++++++++++-- .../src/lib/unsorted/ui/Link.svelte | 4 +++- ...ote.stories.svelte => Note.stories.svelte} | 22 ++++++++--------- .../src/lib/unsorted/ui/Note.svelte | 14 +++++++++++ .../src/lib/unsorted/ui/index.js | 3 +-- 9 files changed, 53 insertions(+), 75 deletions(-) delete mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte delete mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Card.svelte delete mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Footnote.svelte rename packages/ui/core-components/src/lib/unsorted/ui/{Footnote.stories.svelte => Note.stories.svelte} (81%) create mode 100644 packages/ui/core-components/src/lib/unsorted/ui/Note.svelte diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte deleted file mode 100644 index 02b2ef5075..0000000000 --- a/packages/ui/core-components/src/lib/unsorted/ui/Card.stories.svelte +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - {@const data = Query.create(`select * from numeric_series`, query)} - - - - diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Card.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Card.svelte deleted file mode 100644 index 3e47d9a943..0000000000 --- a/packages/ui/core-components/src/lib/unsorted/ui/Card.svelte +++ /dev/null @@ -1,14 +0,0 @@ - - - - -
- -
diff --git a/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte b/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte index 59d2449295..cfb37f234f 100644 --- a/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte +++ b/packages/ui/core-components/src/lib/unsorted/ui/Embed.svelte @@ -3,6 +3,11 @@