From dd1cd7da34b1f3746048e903ce4fe15c70a40335 Mon Sep 17 00:00:00 2001 From: Jakub Freisler Date: Fri, 22 Sep 2023 10:34:16 +0200 Subject: [PATCH 1/5] feat: alert block component [SV-155] Signed-off-by: Jakub Freisler --- .../.vuepress/components/Showcase.vue | 15 +++- apps/docs/components/blocks/Alert.md | 71 ++++++++++++++----- .../nuxt/pages/showcases/Alert/Alert.vue | 48 +++++++++++++ .../nuxt/pages/showcases/Alert/AlertError.vue | 54 +++++++++----- .../pages/showcases/Alert/AlertNeutral.vue | 17 +++-- .../pages/showcases/Alert/AlertPositive.vue | 39 ++++++---- .../pages/showcases/Alert/AlertSecondary.vue | 17 +++-- .../pages/showcases/Alert/AlertWarning.vue | 44 ++++++++---- 8 files changed, 228 insertions(+), 77 deletions(-) create mode 100644 apps/preview/nuxt/pages/showcases/Alert/Alert.vue diff --git a/apps/docs/components/.vuepress/components/Showcase.vue b/apps/docs/components/.vuepress/components/Showcase.vue index cc27ddbe66..82091e88e9 100644 --- a/apps/docs/components/.vuepress/components/Showcase.vue +++ b/apps/docs/components/.vuepress/components/Showcase.vue @@ -9,9 +9,17 @@ Preview + @@ -30,7 +38,12 @@ -
+
+ + + +
+
diff --git a/apps/docs/components/blocks/Alert.md b/apps/docs/components/blocks/Alert.md index aace17a73b..e7fd17ca77 100644 --- a/apps/docs/components/blocks/Alert.md +++ b/apps/docs/components/blocks/Alert.md @@ -12,69 +12,106 @@ hideToc: true Simple version of alert that has neutral grey color. - + +::: slot usage <<<../../preview/nuxt/pages/showcases/Alert/AlertNeutral.vue <<<../../preview/next/pages/showcases/Alert/AlertNeutral.tsx#source +::: - - -## Alert positive - -Green color indicates that an action went successful. - - -<<<../../preview/nuxt/pages/showcases/Alert/AlertPositive.vue +<<<../../preview/nuxt/pages/showcases/Alert/Alert.vue -<<<../../preview/next/pages/showcases/Alert/AlertPositive.tsx#source + + ## Alert secondary This type is informative just like neutral except that its palette is more noticeable. - + +::: slot usage <<<../../preview/nuxt/pages/showcases/Alert/AlertSecondary.vue <<<../../preview/next/pages/showcases/Alert/AlertSecondary.tsx#source +::: + +<<<../../preview/nuxt/pages/showcases/Alert/Alert.vue + + + + + + +## Alert positive + +Green color indicates that an action went successful. + + +::: slot usage + +<<<../../preview/nuxt/pages/showcases/Alert/AlertPositive.vue + + +<<<../../preview/next/pages/showcases/Alert/AlertPositive.tsx#source + +::: + +<<<../../preview/nuxt/pages/showcases/Alert/Alert.vue + + + + ## Alert warning Alert can be more descriptive and its content can be splitted into title and description. - - + +::: slot usage <<<../../preview/nuxt/pages/showcases/Alert/AlertWarning.vue <<<../../preview/next/pages/showcases/Alert/AlertWarning.tsx#source - +::: + +<<<../../preview/nuxt/pages/showcases/Alert/Alert.vue + + + + ## Alert error This type is usually used for information displayed when an important problem occurs. - - + +::: slot usage <<<../../preview/nuxt/pages/showcases/Alert/AlertError.vue <<<../../preview/next/pages/showcases/Alert/AlertError.tsx#source - +::: + +<<<../../preview/nuxt/pages/showcases/Alert/Alert.vue + + + + diff --git a/apps/preview/nuxt/pages/showcases/Alert/Alert.vue b/apps/preview/nuxt/pages/showcases/Alert/Alert.vue new file mode 100644 index 0000000000..719cccf380 --- /dev/null +++ b/apps/preview/nuxt/pages/showcases/Alert/Alert.vue @@ -0,0 +1,48 @@ + + + + + diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue index 634452941e..f575c5946b 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue @@ -1,25 +1,41 @@ diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue index a5f34d30cd..043bb6876b 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue @@ -1,8 +1,15 @@ + + diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue index 960ea5e6f7..80472f11ec 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue @@ -1,21 +1,32 @@ diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertSecondary.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertSecondary.vue index 4543048f86..69f99ca960 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertSecondary.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertSecondary.vue @@ -1,13 +1,18 @@ diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertWarning.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertWarning.vue index 0bf79ff313..1fa9407e5c 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertWarning.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertWarning.vue @@ -1,22 +1,36 @@ From f6cc051478247bde004cb52ff82d41f80d5be2b3 Mon Sep 17 00:00:00 2001 From: Jakub Freisler Date: Mon, 25 Sep 2023 10:37:10 +0200 Subject: [PATCH 2/5] chore: alert rewrite block component Signed-off-by: Jakub Freisler --- .../.vuepress/components/Showcase.vue | 23 +++++--- apps/docs/components/blocks/Alert.md | 18 +++--- apps/docs/components/react/blocks.md | 4 ++ apps/docs/components/vue/blocks.md | 4 ++ .../next/pages/showcases/Alert/Alert.tsx | 56 ++++++++++++++++++ .../next/pages/showcases/Alert/AlertError.tsx | 58 ++++++++++++------- .../pages/showcases/Alert/AlertNeutral.tsx | 14 +++-- .../pages/showcases/Alert/AlertPositive.tsx | 39 ++++++++----- .../pages/showcases/Alert/AlertSecondary.tsx | 17 ++++-- .../pages/showcases/Alert/AlertWarning.tsx | 44 +++++++++----- .../nuxt/pages/showcases/Alert/Alert.vue | 44 ++++++-------- .../nuxt/pages/showcases/Alert/AlertError.vue | 17 +++--- .../pages/showcases/Alert/AlertNeutral.vue | 6 +- .../pages/showcases/Alert/AlertPositive.vue | 16 ++--- .../pages/showcases/Alert/AlertSecondary.vue | 8 +-- .../pages/showcases/Alert/AlertWarning.vue | 16 ++--- .../vue/components/SfInput/SfInput.vue | 4 +- 17 files changed, 254 insertions(+), 134 deletions(-) create mode 100644 apps/preview/next/pages/showcases/Alert/Alert.tsx diff --git a/apps/docs/components/.vuepress/components/Showcase.vue b/apps/docs/components/.vuepress/components/Showcase.vue index 82091e88e9..6b38459d08 100644 --- a/apps/docs/components/.vuepress/components/Showcase.vue +++ b/apps/docs/components/.vuepress/components/Showcase.vue @@ -14,14 +14,14 @@ class="px-3 py-2 border-b-2 dark:border-zinc-700" :class="[tab === 2 ? 'text-black dark:text-white border-green dark:border-green' : '']" > - Usage + Source
@@ -33,7 +33,14 @@ @touchstart="eventDownListener" >
- + @@ -61,11 +68,11 @@ export default { }, noPaddings: { type: Boolean, - default: false + default: false, }, noScale: { type: Boolean, - default: false + default: false, }, allow: { type: String, @@ -87,7 +94,7 @@ export default { document.addEventListener('mousemove', this.eventMoveListener); document.addEventListener('touchmove', this.eventMoveListener); document.addEventListener('mouseup', this.eventUpListener); - document.addEventListener('touchup', this.eventUpListener) + document.addEventListener('touchup', this.eventUpListener); }, unmounted() { document.removeEventListener('mousemove', this.eventMoveListener); diff --git a/apps/docs/components/blocks/Alert.md b/apps/docs/components/blocks/Alert.md index e7fd17ca77..8aa6172a99 100644 --- a/apps/docs/components/blocks/Alert.md +++ b/apps/docs/components/blocks/Alert.md @@ -1,7 +1,7 @@ --- layout: DefaultLayout hideBreadcrumbs: true -description: Alert is a notification that keeps people informed of the status of the system and which may or not require the user respond. +description: Alert is a notification that keeps people informed of the status of the system and which may or not require the user response. hideToc: true --- # Alert @@ -10,7 +10,7 @@ hideToc: true ## Alert neutral -Simple version of alert that has neutral grey color. +A simple version of the alert that has a neutral grey color. @@ -27,7 +27,7 @@ Simple version of alert that has neutral grey color. <<<../../preview/nuxt/pages/showcases/Alert/Alert.vue - +<<<../../preview/next/pages/showcases/Alert/Alert.tsx#source @@ -49,13 +49,13 @@ This type is informative just like neutral except that its palette is more notic <<<../../preview/nuxt/pages/showcases/Alert/Alert.vue - +<<<../../preview/next/pages/showcases/Alert/Alert.tsx#source ## Alert positive -Green color indicates that an action went successful. +A green color indicates that an action was successful. ::: slot usage @@ -70,13 +70,13 @@ Green color indicates that an action went successful. <<<../../preview/nuxt/pages/showcases/Alert/Alert.vue - +<<<../../preview/next/pages/showcases/Alert/Alert.tsx#source ## Alert warning -Alert can be more descriptive and its content can be splitted into title and description. +Alert can be more descriptive and its content can be split into title and description. ::: slot usage @@ -91,7 +91,7 @@ Alert can be more descriptive and its content can be splitted into title and des <<<../../preview/nuxt/pages/showcases/Alert/Alert.vue - +<<<../../preview/next/pages/showcases/Alert/Alert.tsx#source @@ -112,6 +112,6 @@ This type is usually used for information displayed when an important problem oc <<<../../preview/nuxt/pages/showcases/Alert/Alert.vue - +<<<../../preview/next/pages/showcases/Alert/Alert.tsx#source diff --git a/apps/docs/components/react/blocks.md b/apps/docs/components/react/blocks.md index a66e5b57a1..8e5f9f4d05 100644 --- a/apps/docs/components/react/blocks.md +++ b/apps/docs/components/react/blocks.md @@ -13,4 +13,8 @@ hideToc: true Fully accessible UI blocks, designed to integrate beautifully with Tailwind CSS and Vue. ::: +::: tip +Some blocks contain "Block Code" tab with our proposition of a reusable component code. Copy it over into your project to use the rest of the examples for such a block. +::: + diff --git a/apps/docs/components/vue/blocks.md b/apps/docs/components/vue/blocks.md index 457213e37f..5d28537fcc 100644 --- a/apps/docs/components/vue/blocks.md +++ b/apps/docs/components/vue/blocks.md @@ -13,4 +13,8 @@ hideToc: true Fully accessible UI blocks, designed to integrate beautifully with Tailwind CSS and Vue. ::: +::: tip +Some blocks contain "Block Code" tab with our proposition of a reusable component code. Copy it over into your project to use the rest of the examples for such a block. +::: + diff --git a/apps/preview/next/pages/showcases/Alert/Alert.tsx b/apps/preview/next/pages/showcases/Alert/Alert.tsx new file mode 100644 index 0000000000..63f497d929 --- /dev/null +++ b/apps/preview/next/pages/showcases/Alert/Alert.tsx @@ -0,0 +1,56 @@ +import { ShowcasePageLayout } from '../../showcases'; +// #region source +import type { PropsWithStyle } from '@storefront-ui/react'; +import { type PropsWithChildren, forwardRef } from 'react'; +import classNames from 'classnames'; + +const sizeClasses = { + sm: 'typography-text-sm', + base: 'typography-text-base', +}; +const variantClasses = { + primary: 'border-primary-200 bg-primary-100', + secondary: 'border-secondary-200 bg-secondary-100', + positive: 'border-positive-200 bg-positive-100', + warning: 'border-warning-200 bg-warning-100', + negative: 'border-negative-200 bg-negative-100', + neutral: 'border-neutral-200 bg-neutral-100', +}; + +export interface AlertProps + extends React.ButtonHTMLAttributes, + PropsWithStyle, + PropsWithChildren { + size?: keyof typeof sizeClasses, + variant?: keyof typeof variantClasses +} + +const Alert = forwardRef((props, ref) => { + const { + className, + size = 'base', + variant = 'neutral', + children, + ...attributes + } = props; + + return ( +
+ {children} +
+ ); +}); + +export default Alert; +// #endregion source +Alert.getLayout = ShowcasePageLayout; diff --git a/apps/preview/next/pages/showcases/Alert/AlertError.tsx b/apps/preview/next/pages/showcases/Alert/AlertError.tsx index 1dae9ba836..0743af12ec 100644 --- a/apps/preview/next/pages/showcases/Alert/AlertError.tsx +++ b/apps/preview/next/pages/showcases/Alert/AlertError.tsx @@ -1,28 +1,46 @@ import { ShowcasePageLayout } from '../../showcases'; // #region source -import { SfIconClose } from '@storefront-ui/react'; +import { SfIconError, SfIconClose } from '@storefront-ui/react'; +import Alert from './Alert'; export default function AlertError() { return ( -
-

The password change was failed.

- - +
+ + +

The password change was failed.

+ + +
+ + + +

The password change was failed.

+ + +
); } diff --git a/apps/preview/next/pages/showcases/Alert/AlertNeutral.tsx b/apps/preview/next/pages/showcases/Alert/AlertNeutral.tsx index f268a2e497..6eb0b31224 100644 --- a/apps/preview/next/pages/showcases/Alert/AlertNeutral.tsx +++ b/apps/preview/next/pages/showcases/Alert/AlertNeutral.tsx @@ -1,13 +1,17 @@ import { ShowcasePageLayout } from '../../showcases'; // #region source +import Alert from './Alert'; export default function AlertNeutral() { return ( -
-

Happy shopping!

+
+ +

Happy shopping!

+
+ + +

Happy shopping!

+
); } diff --git a/apps/preview/next/pages/showcases/Alert/AlertPositive.tsx b/apps/preview/next/pages/showcases/Alert/AlertPositive.tsx index 252e42b3c8..a7632efa80 100644 --- a/apps/preview/next/pages/showcases/Alert/AlertPositive.tsx +++ b/apps/preview/next/pages/showcases/Alert/AlertPositive.tsx @@ -1,23 +1,34 @@ import { ShowcasePageLayout } from '../../showcases'; // #region source import { SfIconCheckCircle, SfIconClose } from '@storefront-ui/react'; +import Alert from './Alert'; export default function AlertPositive() { return ( -
- -

The product has been added to the cart.

- +
+ + +

The product has been added to the cart.

+ +
+ + + +

The product has been added to the cart.

+ +
); } diff --git a/apps/preview/next/pages/showcases/Alert/AlertSecondary.tsx b/apps/preview/next/pages/showcases/Alert/AlertSecondary.tsx index 2e34f6e421..a0901bb303 100644 --- a/apps/preview/next/pages/showcases/Alert/AlertSecondary.tsx +++ b/apps/preview/next/pages/showcases/Alert/AlertSecondary.tsx @@ -1,15 +1,20 @@ import { ShowcasePageLayout } from '../../showcases'; // #region source import { SfIconInfo } from '@storefront-ui/react'; +import Alert from './Alert'; export default function AlertSecondary() { return ( -
- -

Your cart will soon be full.

+
+ + +

Your cart will soon be full.

+
+ + + +

Your cart will soon be full.

+
); } diff --git a/apps/preview/next/pages/showcases/Alert/AlertWarning.tsx b/apps/preview/next/pages/showcases/Alert/AlertWarning.tsx index 85074fe029..a81d033e52 100644 --- a/apps/preview/next/pages/showcases/Alert/AlertWarning.tsx +++ b/apps/preview/next/pages/showcases/Alert/AlertWarning.tsx @@ -1,24 +1,38 @@ import { ShowcasePageLayout } from '../../showcases'; // #region source import { SfIconWarning } from '@storefront-ui/react'; +import Alert from './Alert'; export default function AlertWarning() { return ( -
- -
-

Your account

-

Your shipping details need to be updated.

-
- +
+ + +
+

Your account

+

Your shipping details need to be updated.

+
+ +
+ + + +
+

Your account

+

Your shipping details need to be updated.

+
+ +
); } diff --git a/apps/preview/nuxt/pages/showcases/Alert/Alert.vue b/apps/preview/nuxt/pages/showcases/Alert/Alert.vue index 719cccf380..401d8ab4db 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/Alert.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/Alert.vue @@ -1,5 +1,12 @@ @@ -9,40 +16,27 @@ const sizeClasses = { sm: 'typography-text-sm', base: 'typography-text-base', }; +const variantClasses = { + primary: 'border-primary-200 bg-primary-100', + secondary: 'border-secondary-200 bg-secondary-100', + positive: 'border-positive-200 bg-positive-100', + warning: 'border-warning-200 bg-warning-100', + negative: 'border-negative-200 bg-negative-100', + neutral: 'border-neutral-200 bg-neutral-100', +}; diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue index f575c5946b..0accb8427f 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertError.vue @@ -1,10 +1,11 @@ + diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue index 043bb6876b..979cc07a51 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertNeutral.vue @@ -1,11 +1,11 @@ diff --git a/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue b/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue index 80472f11ec..3e5c01b81f 100644 --- a/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue +++ b/apps/preview/nuxt/pages/showcases/Alert/AlertPositive.vue @@ -1,23 +1,23 @@