Skip to content

Commit

Permalink
Add Adaptive Cards styling to full bundle options
Browse files Browse the repository at this point in the history
  • Loading branch information
corinagum committed Mar 30, 2021
1 parent 5251df1 commit 0bd9611
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions __tests__/adaptiveCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scrollToBottomCompleted from './setup/conditions/scrollToBottomCompleted'
import uiConnected from './setup/conditions/uiConnected';

import createAdaptiveCardsHostConfig from '../packages/bundle/src/adaptiveCards/Styles/adaptiveCardHostConfig';
import defaultStyleOptions from '../packages/api/src/defaultStyleOptions';
import fullBundleDefaultStyleOptions from '../packages/bundle/src/fullBundleDefaultStyleOptions';

// selenium-webdriver API doc:
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html
Expand Down Expand Up @@ -57,7 +57,7 @@ test('action styles', async () => {
});

test('breakfast card with custom host config', async () => {
const adaptiveCardHostConfig = createAdaptiveCardsHostConfig({ ...defaultStyleOptions, bubbleTextColor: '#FF0000' });
const adaptiveCardHostConfig = createAdaptiveCardsHostConfig({ ...fullBundleDefaultStyleOptions, bubbleTextColor: '#FF0000' });

const { driver, pageObjects } = await setupWebDriver({
props: {
Expand Down
17 changes: 11 additions & 6 deletions packages/bundle/src/adaptiveCards/AdaptiveCardsStyleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
type AdaptiveCardStyleOptions = {
type ADAPTIVE_CARD_DEFAULT_STYLE_OPTIONS = {
/**
* Cards styling
* Adaptive Cards styling
*/

// TODO: Put JSDoc on every options.
/**
* Adaptive Cards styling for 'emphasis' container style
*/
cardEmphasisBackgroundColor?: string;

/**
* Cards: Adaptive Card push button
* Adaptive Cards: background color of Adaptive Cards button with status of 'aria-pressed'
*/

cardPushButtonBackgroundColor?: string;

/**
* Adaptive Cards: text color of Adaptive Cards button with status of 'aria-pressed'
*/
cardPushButtonTextColor?: string;

/**
Expand All @@ -20,4 +25,4 @@ type AdaptiveCardStyleOptions = {
richCardWrapTitle?: boolean;
};

export default AdaptiveCardStyleOptions;
export default ADAPTIVE_CARD_DEFAULT_STYLE_OPTIONS;
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import FullBundleStyleOptions from '../../../FullBundleStyleOptions';

export default function ({
cardPushButtonBackgroundColor,
cardPushButtonTextColor,
accent,
paddingRegular,
primaryFont
}) {
}: FullBundleStyleOptions) {
return {
'&.webchat__adaptive-card-renderer': {
'& .ac-input, & .ac-inlineActionButton, & .ac-quickActionButton': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defaultStyleOptions } from 'botframework-webchat-api';
import FullBundleStyleOptions from '../../FullBundleStyleOptions';

// https://docs.microsoft.com/en-us/adaptive-cards/rendering-cards/host-config

export default ({
Expand All @@ -7,7 +8,7 @@ export default ({
cardEmphasisBackgroundColor,
primaryFont,
subtle
} = defaultStyleOptions) => ({
}: FullBundleStyleOptions) => ({
containerStyles: {
default: {
foregroundColors: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { defaultStyleOptions } from 'botframework-webchat-api';

import createAdaptiveCardRendererStyle from './StyleSet/AdaptiveCardRenderer';
import createAnimationCardAttachmentStyle from './StyleSet/AnimationCardAttachment';
import createAudioCardAttachmentStyle from './StyleSet/AudioCardAttachment';
import fullBundleStyleOptions from '../../fullBundleDefaultStyleOptions';

// TODO: [P4] We should add a notice for people who want to use "styleSet" instead of "styleOptions".
// "styleSet" is actually CSS stylesheet and it is based on the DOM tree.
// DOM tree may change from time to time, thus, maintaining "styleSet" becomes a constant effort.

export default function createAdaptiveCardsStyleSet(options) {
options = { ...defaultStyleOptions, ...options };
options = { ...fullBundleStyleOptions, ...options };

return {
adaptiveCardRenderer: createAdaptiveCardRendererStyle(options),
Expand Down
3 changes: 3 additions & 0 deletions packages/bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import createDirectLineSpeechAdapters from './createDirectLineSpeechAdapters';
import createStyleSet from './createFullStyleSet';
import defaultCreateDirectLine from './createDirectLine';
import defaultCreateDirectLineAppServiceExtension from './createDirectLineAppServiceExtension';
import fullBundleDefaultStyleOptions from './fullBundleDefaultStyleOptions';
import FullComposer from './FullComposer';
import HeroCardContent from './adaptiveCards/Attachment/HeroCardContent';
import OAuthCardContent from './adaptiveCards/Attachment/OAuthCardContent';
Expand Down Expand Up @@ -79,6 +80,7 @@ export {
createCognitiveServicesSpeechServicesPonyfillFactory,
createDirectLineSpeechAdapters,
createStyleSet,
fullBundleDefaultStyleOptions,
patchedHooks as hooks,
renderMarkdown,
renderWebChat
Expand All @@ -94,6 +96,7 @@ window['WebChat'] = {
createDirectLineAppServiceExtension,
createDirectLineSpeechAdapters,
createStyleSet,
fullBundleDefaultStyleOptions,
hooks: patchedHooks,
ReactWebChat,
renderMarkdown,
Expand Down
5 changes: 3 additions & 2 deletions packages/bundle/src/useComposerProps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useMemo } from 'react';

import { concatMiddleware, defaultStyleOptions } from 'botframework-webchat-component';
import { concatMiddleware } from 'botframework-webchat-component';
import createAdaptiveCardsAttachmentForScreenReaderMiddleware from './adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware';
import createAdaptiveCardsAttachmentMiddleware from './adaptiveCards/createAdaptiveCardsAttachmentMiddleware';
import createAdaptiveCardsStyleSet from './adaptiveCards/Styles/createAdaptiveCardsStyleSet';
import fullBundleStyleOptions from './fullBundleDefaultStyleOptions';
import defaultRenderMarkdown from './renderMarkdown';

export default function useComposerProps({
Expand All @@ -24,7 +25,7 @@ export default function useComposerProps({
[attachmentForScreenReaderMiddleware]
);

const patchedStyleOptions = useMemo(() => ({ ...defaultStyleOptions, ...styleOptions }), [styleOptions]);
const patchedStyleOptions = useMemo(() => ({ ...fullBundleStyleOptions, ...styleOptions }), [styleOptions]);

// When styleSet is not specified, the styleOptions will be used to create Adaptive Cards styleSet and merged into useStyleSet.
const extraStyleSet = useMemo(() => (styleSet ? undefined : createAdaptiveCardsStyleSet(patchedStyleOptions)), [
Expand Down
6 changes: 1 addition & 5 deletions packages/component/src/Styles/defaultStyleOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const DEFAULT_OPTIONS = {
accent: DEFAULT_ACCENT,
activeActivityOutlineColor: DEFAULT_SUBTLE,
backgroundColor: 'White',
cardEmphasisBackgroundColor: '#F0F0F0',
paddingRegular: PADDING_REGULAR,
paddingWide: PADDING_REGULAR * 2,
subtle: DEFAULT_SUBTLE,
Expand Down Expand Up @@ -213,10 +212,7 @@ const DEFAULT_OPTIONS = {

transcriptVisualKeyboardIndicatorColor: 'Black',
transcriptVisualKeyboardIndicatorStyle: 'solid',
transcriptVisualKeyboardIndicatorWidth: 2,
//AdaptiveCard push button
cardPushButtonBackgroundColor: '#0063B1',
cardPushButtonTextColor: 'white'
transcriptVisualKeyboardIndicatorWidth: 2
};

export default DEFAULT_OPTIONS;

0 comments on commit 0bd9611

Please sign in to comment.