From a37b133d705c10dc1ad88efe7726e5bbc7c51f3d Mon Sep 17 00:00:00 2001 From: Patricia Mihut Date: Mon, 20 Dec 2021 11:56:16 +0200 Subject: [PATCH] fix(AdaptiveCards): implement generic handling of adaptive card properties --- .../AdaptiveCard.stories.storyshot | 497 +++++++++--------- .../adaptive-cards/Column/Column.jsx | 42 +- .../adaptive-cards/Column/Column.scss | 15 - .../adaptive-cards/ColumnSet/ColumnSet.jsx | 43 +- .../adaptive-cards/ColumnSet/ColumnSet.scss | 10 - .../adaptive-cards/Component/Component.jsx | 68 ++- .../adaptive-cards/Component/Component.scss | 69 ++- .../adaptive-cards/Container/Container.jsx | 51 +- .../adaptive-cards/Container/Container.scss | 13 - src/components/adaptive-cards/Image/Image.jsx | 50 +- .../adaptive-cards/Image/Image.scss | 14 - .../adaptive-cards/ImageSet/ImageSet.jsx | 31 +- .../adaptive-cards/TextBlock/TextBlock.jsx | 48 +- .../adaptive-cards/TextBlock/TextBlock.scss | 35 -- .../adaptive-cards/_adaptive-cards.scss | 5 - 15 files changed, 487 insertions(+), 504 deletions(-) delete mode 100644 src/components/adaptive-cards/Column/Column.scss delete mode 100644 src/components/adaptive-cards/ColumnSet/ColumnSet.scss delete mode 100644 src/components/adaptive-cards/Container/Container.scss delete mode 100644 src/components/adaptive-cards/Image/Image.scss delete mode 100644 src/components/adaptive-cards/TextBlock/TextBlock.scss diff --git a/src/components/adaptive-cards/AdaptiveCard/__snapshots__/AdaptiveCard.stories.storyshot b/src/components/adaptive-cards/AdaptiveCard/__snapshots__/AdaptiveCard.stories.storyshot index 69c3544f1..58a47bbd4 100644 --- a/src/components/adaptive-cards/AdaptiveCard/__snapshots__/AdaptiveCard.stories.storyshot +++ b/src/components/adaptive-cards/AdaptiveCard/__snapshots__/AdaptiveCard.stories.storyshot @@ -6,13 +6,13 @@ Array [ className="wxc-adaptive-card" >
Cisco Webex Teams
Buttons and Cards Release
Release Date:
Product:
OS:
Aug 6, 2019
Webex Teams
Mac, Windows, Web
We're making it easier for you to interact with bots and integrations in Webex Teams. When your bot sends information in a space that includes a card with buttons, you can now easily interact with it.
Buttons and Cards Resources:
[Developer Portal Buttons and Cards Guide]()
@@ -137,7 +137,8 @@ Array [ } } ], - "horizontalAlignment": "Left" + "horizontalAlignment": "Left", + "spacing": "None" }
@@ -171,18 +172,18 @@ Array [ className="wxc-adaptive-card" >
Column 1
Column 2
Column 3
You can even repeat the background image...
Those are some neat arrows
Horizontal repeat...
Vertical repeat...
Bleed left
Column 1
Column 2
Column 3
Bleed center
Column 1
Column 2
Column 3
Bleed right
Column 1
Column 2
Column 3
Bleed all
Column 1
Column 2
Column 3
@@ -468,7 +469,7 @@ Array [
@@ -484,29 +485,29 @@ Array [
This is a column
The columnset has a minHeight of 100px while this column has a minHeight of 200px so it should override
@@ -537,52 +538,52 @@ Array [
The middle column is set to rtl
Column One
العمود الثاني
Column three
SHADES
Dec 4
Final
7 - 40
SKINS
@@ -640,23 +641,23 @@ Array [
Try clicking a column!
Column 1
Column 2
Column 3
No Style
Default Style
Emphasis Style
Container no style
Container default style
Container emphasis style
@@ -767,41 +768,41 @@ Array [
Hi,
MasterHip
Column 1
(auto)
(stretch)
(auto)
Pick up where you left off?
Silver Star Mountain
Maps
Kitchen Remodel
With EMPHASIS
The Witcher
Netflix
@@ -1016,15 +1017,15 @@ Array [ className="wxc-adaptive-card" >
This is some text
This container has the default style
color: default
color: accent
color: good
color: warning
color: attention
color: light
color: dark
This container has the accent style
color: default
color: accent
color: good
color: warning
color: attention
color: light
color: dark
Contained container - no style
Contained container - emphasis
Contained container - default
Contained container - good
Contained container - warning
Contained container - attention
Contained container - accent
@@ -1216,7 +1217,7 @@ Array [ className="wxc-adaptive-card" >
color: default
color: accent
color: good
color: warning
color: attention
color: light
color: dark
Font type not set.
Font type set to *default*.
Font type set to *monospace*.
**horizontalAlignment:left**
**horizontalAlignment:center**
**horizontalAlignment:right**
isSubtle:false
isSubtle:true
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
size:default
size:small
size:default
size:medium
size:large
size:extraLarge
weight: lighter
weight: default
weight: bolder
**wrap: false** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat
**wrap: true** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Style set to heading
Style set to heading, color set to good
Style set to default
Style unset
diff --git a/src/components/adaptive-cards/Column/Column.jsx b/src/components/adaptive-cards/Column/Column.jsx index 1960be725..cddc4bec3 100644 --- a/src/components/adaptive-cards/Column/Column.jsx +++ b/src/components/adaptive-cards/Column/Column.jsx @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import Component, {registerComponent} from '../Component/Component'; +import Component, {acPropTypes, registerComponent} from '../Component/Component'; import webexComponentClasses from '../../helpers'; /** @@ -9,28 +9,14 @@ import webexComponentClasses from '../../helpers'; * * @param {object} props React props passed to the component * @param {object} props.data Active cards definition + * @param {string} props.className Custom CSS class to apply * @returns {object} JSX of the component */ -export default function Column({data}) { - const [cssClasses, sc] = webexComponentClasses('column'); - const classes = []; - const getClass = (key, value) => sc(`${key}--${value}`); - - for (const [key, value] of Object.entries(data)) { - switch (key) { - case 'items': break; - case 'bleed': - case 'rtl': - case 'style': - classes.push(getClass(key, value)); - break; - default: - console.log('[Column]', 'Unknown property:', key, value); - } - } +export default function Column({data, className}) { + const [cssClasses] = webexComponentClasses('adaptive-cards-column', className); return ( -
+
{/* eslint-disable react/no-array-index-key */} {data.items?.map((item, index) => )}
@@ -39,6 +25,22 @@ export default function Column({data}) { Column.propTypes = { data: PropTypes.shape().isRequired, + className: PropTypes.string, +}; + +Column.defaultProps = { + className: '', +}; + +Column.acPropTypes = { + id: acPropTypes.id, + isVisible: acPropTypes.isVisible, + items: acPropTypes.children, + rtl: acPropTypes.rtl, + separator: acPropTypes.separator, + spacing: acPropTypes.spacing, + style: acPropTypes.containerStyle, + type: acPropTypes.type, }; -registerComponent('Column', Column); +registerComponent('Column', Column, 'vertical'); diff --git a/src/components/adaptive-cards/Column/Column.scss b/src/components/adaptive-cards/Column/Column.scss deleted file mode 100644 index 27d108291..000000000 --- a/src/components/adaptive-cards/Column/Column.scss +++ /dev/null @@ -1,15 +0,0 @@ -$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-column; - -.#{$C}__bleed--false { padding: 0.625rem; } - -.#{$C}__rtl--true { direction: rtl; } -.#{$C}__rtl--false { direction: ltr; } - -.#{$C}__style { - &--default { background-color: var(--wxc-adaptive-cards--background-color--default); } - &--emphasis { background-color: var(--wxc-adaptive-cards--background-color--emphasis); } - &--good { background-color: var(--wxc-adaptive-cards--background-color--good); } - &--attention { background-color: var(--wxc-adaptive-cards--background-color--attention); } - &--warning { background-color: var(--wxc-adaptive-cards--background-color--warning); } - &--accent { background-color: var(--wxc-adaptive-cards--background-color--accent); } -} diff --git a/src/components/adaptive-cards/ColumnSet/ColumnSet.jsx b/src/components/adaptive-cards/ColumnSet/ColumnSet.jsx index 2cb4f81cc..9a66f1b72 100644 --- a/src/components/adaptive-cards/ColumnSet/ColumnSet.jsx +++ b/src/components/adaptive-cards/ColumnSet/ColumnSet.jsx @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import Component, {registerComponent} from '../Component/Component'; +import Component, {acPropTypes, registerComponent} from '../Component/Component'; import webexComponentClasses from '../../helpers'; /** @@ -13,27 +13,18 @@ import webexComponentClasses from '../../helpers'; * @returns {object} JSX of the component */ export default function ColumnSet({data, className}) { - const [cssClasses, sc] = webexComponentClasses('adaptive-cards-column-set', className); - const classes = []; - const getClass = (key, value) => sc(`${key}--${value}`); - - for (const [key, value] of Object.entries(data)) { - switch (key) { - case 'columns': break; - case 'style': - classes.push(getClass(key, value)); - break; - default: - console.log('[ColumnSet]', 'Unknown property:', key, value); - } - } + const [cssClasses] = webexComponentClasses('adaptive-cards-column-set', className); return ( -
+
{/* eslint-disable react/no-array-index-key */} - {data.columns.map((item, index) => ( - - ))} + {data.columns.map((item, index) => { + const itemData = {type: 'Column', ...item}; + + return ( + + ); + })}
); } @@ -47,4 +38,16 @@ ColumnSet.defaultProps = { className: '', }; -registerComponent('ColumnSet', ColumnSet, 'vertical'); +ColumnSet.acPropTypes = { + columns: acPropTypes.children, + horizontalAlignment: acPropTypes.horizontalAlignment, + id: acPropTypes.id, + isVisible: acPropTypes.isVisible, + minHeight: acPropTypes.minHeight, + separator: acPropTypes.separator, + spacing: acPropTypes.spacing, + style: acPropTypes.containerStyle, + type: acPropTypes.type, +}; + +registerComponent('ColumnSet', ColumnSet, 'horizontal'); diff --git a/src/components/adaptive-cards/ColumnSet/ColumnSet.scss b/src/components/adaptive-cards/ColumnSet/ColumnSet.scss deleted file mode 100644 index f3ae997e7..000000000 --- a/src/components/adaptive-cards/ColumnSet/ColumnSet.scss +++ /dev/null @@ -1,10 +0,0 @@ -$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-adaptive-cards-column-set; - -.#{$C}__style { - &--default { background-color: var(--wxc-adaptive-cards--background-color--default); } - &--emphasis { background-color: var(--wxc-adaptive-cards--background-color--emphasis); } - &--good { background-color: var(--wxc-adaptive-cards--background-color--good); } - &--attention { background-color: var(--wxc-adaptive-cards--background-color--attention); } - &--warning { background-color: var(--wxc-adaptive-cards--background-color--warning); } - &--accent { background-color: var(--wxc-adaptive-cards--background-color--accent); } -} diff --git a/src/components/adaptive-cards/Component/Component.jsx b/src/components/adaptive-cards/Component/Component.jsx index 23aeda298..8eee61156 100644 --- a/src/components/adaptive-cards/Component/Component.jsx +++ b/src/components/adaptive-cards/Component/Component.jsx @@ -5,6 +5,26 @@ import webexComponentClasses from '../../helpers'; const componentTypes = {}; const containerTypes = {}; +export const acPropTypes = { + children: 'children', + containerStyle: 'container-style', + defaultImageSize: 'default-image-size', + fontType: 'font-type', + horizontalAlignment: 'horizontal-alignment', + id: 'id', + imageSize: 'image-size', + imageStyle: 'image-style', + isVisible: 'is-visible', + rtl: 'rtl', + separator: 'separator', + size: 'size', + spacing: 'spacing', + text: 'text', + type: 'type', + weight: 'weight', + wrap: 'wrap', +}; + /** * Registers a component * @@ -47,29 +67,29 @@ UnknownComponent.defaultProps = { * * @param {object} props React properties * @param {object} props.data Active Cards definition - * @param {string} [props.type] Active Cards type definition - * @param {object} props.parentData Parent Card definition * @returns {object} JSX of the component */ -export default function Component({data, type, parentData}) { - const [cssClasses, sc] = webexComponentClasses('adaptive-cards-component'); +export default function Component({data}) { + const C = componentTypes[data.type] || UnknownComponent; const classes = []; - const getClass = (key, value) => sc(`${key}--${value}`); - const { - separator, - spacing, - isVisible, - ...compData - } = data; + const getClass = (propType, value) => `wxc-ac-${propType}--${value}`; - for (const [key, value] of Object.entries(data)) { - switch (key) { - case 'separator': - case 'spacing': - case 'isVisible': - classes.push(getClass(key, value)); + for (const [prop, value] of Object.entries(data)) { + const propType = (C.acPropTypes && C.acPropTypes[prop]) || undefined; + + switch (propType) { + case undefined: + console.log('Unknown property', prop); + break; + case acPropTypes.action: + case acPropTypes.children: + case acPropTypes.defaultImageSize: + case acPropTypes.id: + case acPropTypes.text: + case acPropTypes.type: break; default: + classes.push(getClass(propType, value)); break; } } @@ -80,24 +100,14 @@ export default function Component({data, type, parentData}) { classes.push(getClass('container', containerType)); } - const C = componentTypes[data.type || type] || UnknownComponent; - return ( ); } Component.propTypes = { data: PropTypes.shape().isRequired, - type: PropTypes.string, - parentData: PropTypes.shape(), -}; - -Component.defaultProps = { - type: undefined, - parentData: {}, }; diff --git a/src/components/adaptive-cards/Component/Component.scss b/src/components/adaptive-cards/Component/Component.scss index 0b3f7a5c3..993d8526d 100644 --- a/src/components/adaptive-cards/Component/Component.scss +++ b/src/components/adaptive-cards/Component/Component.scss @@ -1,15 +1,68 @@ -$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-adaptive-cards-component; +$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-ac; -.#{$C}__container--horizontal { +.#{$C}-font-type--monospace { font-family: #{$font-family-monospace}; } +.#{$C}-font-type--default { font-family: #{$brand-font-regular}; } + +.#{$C}-horizontal-alignment { + &--left { text-align: left; } + &--center { text-align: center; } + &--right { text-align: right; } +} + +.#{$C}-size { + &--default { font-size: 0.875rem; } + &--small { font-size: 0.75rem; } + &--medium { font-size: 1rem; } + &--large { font-size: 1.25rem; } + &--extraLarge { font-size: 1.5rem; } +} + +.#{$C}-weight { + &--default { font-weight: 400; } + &--lighter { font-weight: lighter; } + &--bolder { font-weight: bolder; } +} + +.#{$C}-wrap--false { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.#{$C}-rtl--true { direction: rtl; } +.#{$C}-rtl--false { direction: ltr; } + +.#{$C}-container-style { + &--heading { + font-weight: bold; + font-size: 200%; + } + &--default { background-color: var(--wxc-adaptive-cards--background-color--default); } + &--emphasis { background-color: var(--wxc-adaptive-cards--background-color--emphasis); } + &--good { background-color: var(--wxc-adaptive-cards--background-color--good); } + &--attention { background-color: var(--wxc-adaptive-cards--background-color--attention); } + &--warning { background-color: var(--wxc-adaptive-cards--background-color--warning); } + &--accent { background-color: var(--wxc-adaptive-cards--background-color--accent); } +} + +.#{$C}-image-style--person { border-radius: 50%; } + +.#{$C}-image-size { + &--small { width: 40px; height: 40px; } + &--medium { width: 80px; height: 80px; } + &--large { width: 160px; height: 160px; } +} + +.#{$C}-container--horizontal { display: flex; - > .#{$C}__separator--true:not(:first-child) { + > .#{$C}-separator--true:not(:first-child) { border-left: 1px solid var(--wxc-adaptive-cards--separator-color); } > :not(:first-child) { margin-left: 0.5rem; } - > .#{$C}__spacing:not(:first-child) { + > .#{$C}-spacing:not(:first-child) { &--none { margin-left: 0; } &--small { margin-top: 0.188rem; } &--medium { margin-left: 1.125rem; } @@ -19,17 +72,17 @@ $C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-adaptive-cards-component; } } -.#{$C}__container--vertical { +.#{$C}-container--vertical { display: flex; flex-direction: column; - > .#{$C}__separator--true:not(:first-child) { + > .#{$C}-separator--true:not(:first-child) { border-top: 1px solid var(--wxc-adaptive-cards--separator-color);; } > :not(:first-child) { margin-top: 0.5rem; } - > .#{$C}__spacing:not(:first-child) { + > .#{$C}-spacing:not(:first-child) { &--none { margin-top: 0; } &--small { margin-top: 0.188rem; } &--medium { margin-top: 1.125rem; } @@ -39,7 +92,7 @@ $C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-adaptive-cards-component; } } -.#{$C}__isVisible--false { +.#{$C}-is-visible--false { display: none; } diff --git a/src/components/adaptive-cards/Container/Container.jsx b/src/components/adaptive-cards/Container/Container.jsx index 2faf35775..cb2d33ce3 100644 --- a/src/components/adaptive-cards/Container/Container.jsx +++ b/src/components/adaptive-cards/Container/Container.jsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import webexComponentClasses from '../../helpers'; -import Component, {registerComponent} from '../Component/Component'; +import Component, {acPropTypes, registerComponent} from '../Component/Component'; /** * Adaptive Cards Container component @@ -9,43 +9,40 @@ import Component, {registerComponent} from '../Component/Component'; * * @param {object} props React props passed to the component * @param {object} props.data Active cards definition + * @param {string} props.className Custom CSS class to apply * @returns {object} JSX of the component */ -export default function Container({data}) { - const [, sc] = webexComponentClasses('container'); - const classes = []; - - const getClass = (key, value) => sc(`${key}--${value}`); - - for (const [key, value] of Object.entries(data)) { - switch (key) { - case 'backgroundImage': - case 'bleed': - case 'items': - case 'minHeight': - case 'verticalContentAlignment': - case 'type': - break; - case 'style': - classes.push(getClass(key, value)); - break; - default: - console.log('[Container]', 'Unknown property', key, value); - } - } - - const [cssClasses] = webexComponentClasses('container', classes.join(' ')); +export default function Container({data, className}) { + const [cssClasses] = webexComponentClasses('container', className); return (
- {/* eslint-disable-next-line react/no-array-index-key */} - {data.items.map((item, index) => )} + {/* eslint-disable react/no-array-index-key */} + {data.items.map((item, index) => ( + + ))}
); } Container.propTypes = { data: PropTypes.shape().isRequired, + className: PropTypes.string, +}; + +Container.defaultProps = { + className: '', +}; + +Container.acPropTypes = { + id: acPropTypes.id, + isVisible: acPropTypes.isVisible, + items: acPropTypes.children, + rtl: acPropTypes.rtl, + separator: acPropTypes.separator, + spacing: acPropTypes.spacing, + style: acPropTypes.containerStyle, + type: acPropTypes.type, }; registerComponent('Container', Container, 'vertical'); diff --git a/src/components/adaptive-cards/Container/Container.scss b/src/components/adaptive-cards/Container/Container.scss deleted file mode 100644 index 869c4c6b0..000000000 --- a/src/components/adaptive-cards/Container/Container.scss +++ /dev/null @@ -1,13 +0,0 @@ -$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-container; - -.#{$C} { - background-color: var(--wxc-adaptive-cards--background-color--default); - - &__style{ - &--emphasis { background-color: var(--wxc-adaptive-cards--background-color--emphasis); } - &--accent { background-color: var(--wxc-adaptive-cards--background-color--accent) ;} - &--good { background-color: var(--wxc-adaptive-cards--background-color--good); } - &--attention { background-color: var(--wxc-adaptive-cards--background-color--attention); } - &--warning { background-color: var(--wxc-adaptive-cards--background-color--warning); } - } -} diff --git a/src/components/adaptive-cards/Image/Image.jsx b/src/components/adaptive-cards/Image/Image.jsx index bb661fa7c..8a058a624 100644 --- a/src/components/adaptive-cards/Image/Image.jsx +++ b/src/components/adaptive-cards/Image/Image.jsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import webexComponentClasses from '../../helpers'; -import {registerComponent} from '../Component/Component'; +import {acPropTypes, registerComponent} from '../Component/Component'; /** * Adaptive Cards Image component @@ -9,38 +9,11 @@ import {registerComponent} from '../Component/Component'; * * @param {object} props React props passed to the component * @param {object} props.data Active cards definition - * @param {object} props.parentData Parent card definition + * @param {string} props.className Custom CSS class to apply * @returns {object} JSX of the component */ -export default function Image({data, parentData}) { - const [, sc] = webexComponentClasses('adaptive-cards-image'); - const classes = []; - - const getClass = (key, value) => sc(`${key}--${value}`); - - for (const [key, value] of Object.entries(data)) { - switch (key) { - case 'type': - case 'url': - case 'altText': - case 'backgroundColor': - case 'size': - break; - case 'horizontalAlignment': - case 'isVisible': - case 'separator': - case 'spacing': - case 'style': - classes.push(getClass(key, value)); - break; - default: - console.log('[Image]', 'Unknown property', key, value); - } - } - - classes.push(getClass('size', data.size || parentData.size || 'medium')); - - const [cssClasses] = webexComponentClasses('adaptive-cards-image', classes.join(' ')); +export default function Image({data, className}) { + const [cssClasses] = webexComponentClasses('adaptive-cards-image', className); return ( - {data.images.map((item) => )} + {/* eslint-disable react/no-array-index-key */} + {data.images.map((item, index) => { + const itemData = {size: item.size || data.imageSize || 'medium', ...item}; + + return ( + + ); + })}
); } ImageSet.propTypes = { data: PropTypes.shape().isRequired, + className: PropTypes.string, +}; + +ImageSet.defaultProps = { + className: '', +}; + +ImageSet.acPropTypes = { + images: acPropTypes.children, + id: acPropTypes.id, + imageSize: acPropTypes.defaultImageSize, + isVisible: acPropTypes.isVisible, + separator: acPropTypes.separator, + spacing: acPropTypes.spacing, + type: acPropTypes.type, }; registerComponent('ImageSet', ImageSet, 'horizontal'); diff --git a/src/components/adaptive-cards/TextBlock/TextBlock.jsx b/src/components/adaptive-cards/TextBlock/TextBlock.jsx index 79cfb7d2a..39c04946e 100644 --- a/src/components/adaptive-cards/TextBlock/TextBlock.jsx +++ b/src/components/adaptive-cards/TextBlock/TextBlock.jsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import webexComponentClasses from '../../helpers'; -import {registerComponent} from '../Component/Component'; +import {acPropTypes, registerComponent} from '../Component/Component'; /** * Adaptive Cards TextBlock component @@ -9,33 +9,15 @@ import {registerComponent} from '../Component/Component'; * * @param {object} props React props passed to the component * @param {object} props.data Active cards definition + * @param {string} props.className Custom CSS class to apply * @returns {object} JSX of the component */ -export default function TextBlock({data}) { - const [cssClasses, sc] = webexComponentClasses('text-block', undefined); - const classes = []; - const getClass = (key, value) => sc(`${key}--${value}`); - - for (const [key, value] of Object.entries(data)) { - switch (key) { - case 'type': break; - case 'text': break; - case 'fontType': - case 'horizontalAlignment': - case 'size': - case 'weight': - case 'wrap': - case 'style': - classes.push(getClass(key, value)); - break; - default: - console.log('[TextBlock]', 'Unknown property:', key, value); - } - } +export default function TextBlock({data, className}) { + const [cssClasses] = webexComponentClasses('adaptive-cards-text-block', className); return (
{data.text} @@ -45,6 +27,26 @@ export default function TextBlock({data}) { TextBlock.propTypes = { data: PropTypes.shape().isRequired, + className: PropTypes.string, +}; + +TextBlock.defaultProps = { + className: '', +}; + +TextBlock.acPropTypes = { + fontType: acPropTypes.fontType, + horizontalAlignment: acPropTypes.horizontalAlignment, + id: acPropTypes.id, + isVisible: acPropTypes.isVisible, + separator: acPropTypes.separator, + size: acPropTypes.size, + spacing: acPropTypes.spacing, + style: acPropTypes.containerStyle, + text: acPropTypes.text, + type: acPropTypes.type, + weight: acPropTypes.weight, + wrap: acPropTypes.wrap, }; registerComponent('TextBlock', TextBlock); diff --git a/src/components/adaptive-cards/TextBlock/TextBlock.scss b/src/components/adaptive-cards/TextBlock/TextBlock.scss deleted file mode 100644 index fdf3483cb..000000000 --- a/src/components/adaptive-cards/TextBlock/TextBlock.scss +++ /dev/null @@ -1,35 +0,0 @@ -$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-text-block; - -.#{$C}__fontType--monospace { font-family: #{$font-family-monospace}; } -.#{$C}__fontType--default { font-family: #{$brand-font-regular}; } - -.#{$C}__horizontalAlignment { - &--left { text-align: left; } - &--center { text-align: center; } - &--right { text-align: right; } -} - -.#{$C}__size { - &--default { font-size: 0.875rem; } - &--small { font-size: 0.75rem; } - &--medium { font-size: 1rem; } - &--large { font-size: 1.25rem; } - &--extraLarge { font-size: 1.5rem; } -} - -.#{$C}__weight { - &--default { font-weight: 400; } - &--lighter { font-weight: lighter; } - &--bolder { font-weight: bolder; } -} - -.#{$C}__wrap--false { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} - -.#{$C}__style--heading { - font-weight: bold; - font-size: 200%; -} diff --git a/src/components/adaptive-cards/_adaptive-cards.scss b/src/components/adaptive-cards/_adaptive-cards.scss index 2ae67332b..02851dd30 100644 --- a/src/components/adaptive-cards/_adaptive-cards.scss +++ b/src/components/adaptive-cards/_adaptive-cards.scss @@ -1,8 +1,3 @@ @import 'AdaptiveCard/AdaptiveCard'; -@import 'Column/Column'; -@import 'ColumnSet/ColumnSet'; @import 'Component/Component'; -@import 'Container/Container'; -@import 'Image/Image'; @import 'ImageSet/ImageSet'; -@import 'TextBlock/TextBlock';