Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend style options to support basic adaptive cards style #1670

Merged
merged 9 commits into from
Feb 4, 2019
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added missing Spanish (es-ES) locale by [@schgressive](https://github.com/schgressive) in PR [#1615](https://github.com/Microsoft/BotFramework-WebChat/pull/1615)
- Fix [#1602](https://github.com/Microsoft/BotFramework-WebChat/issues/1602). Fix suggested actions regression of buttons, by [@corinagum](https://github.com/corinagum) in PR [#1616](https://github.com/Microsoft/BotFramework-WebChat/pull/1616)
- `core`: Send `conversationUpdate` activity on connect, by [@compulim](https://github.com/compulim), in PR [#1608](https://github.com/Microsoft/BotFramework-WebChat/pull/1608)
- `component`: Allow font family and adaptive cards text color to be set via styleOptions, by [@a-b-r-o-w-n](https://github.com/a-b-r-o-w-n), in PR [#1670](https://github.com/Microsoft/BotFramework-WebChat/pull/1670)

### Changed
- Moved `botAvatarImage` and `userAvatarImage` to `styleOptions.botAvatarImage` and `styleOptions.userAvatarImage` respectively, in PR [#1486](https://github.com/Microsoft/BotFramework-WebChat/pull/1486)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 0 additions & 31 deletions packages/component/src/Styles/Fonts.js

This file was deleted.

10 changes: 3 additions & 7 deletions packages/component/src/Styles/StyleSet/Avatar.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import {
primaryFont
} from '../Fonts';

export default function createAvatarStyle({
accent,
avatarSize
avatarSize,
primaryFont
}) {
return {
...primaryFont,

alignItems: 'center',
backgroundColor: accent,
borderRadius: '50%',
color: 'White',
display: 'flex',
fontFamily: primaryFont,
height: avatarSize,
justifyContent: 'center',
overflow: 'hidden',
Expand Down
7 changes: 3 additions & 4 deletions packages/component/src/Styles/StyleSet/DictationInterims.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { primaryFont } from '../Fonts';

export default function createDictationInterimsStyle({
paddingRegular
paddingRegular,
primaryFont
}) {
return {
...primaryFont,
fontFamily: primaryFont,
margin: 0,
paddingBottom: 0,
paddingLeft: paddingRegular,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { primaryFont } from '../Fonts';

export default function ({
accent,
bubbleTextColor,
paddingRegular
paddingRegular,
primaryFont
}) {
return {
...primaryFont,
fontFamily: primaryFont,

'& > a': {
alignItems: 'center',
Expand Down
12 changes: 5 additions & 7 deletions packages/component/src/Styles/StyleSet/ErrorBox.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
monospaceSmallFont,
export default function createErrorBoxStyle({
monospaceFont,
primaryFont
} from '../Fonts';

export default function createErrorBoxStyle() {
}) {
return {
...primaryFont,
display: 'flex',
flexDirection: 'column',
fontFamily: primaryFont,
margin: 0,
minHeight: 20,
maxHeight: 200,
Expand All @@ -32,7 +30,7 @@ export default function createErrorBoxStyle() {
padding: 10,

'& > pre': {
...monospaceSmallFont,
fontFamily: monospaceFont,
fontSize: '60%',
margin: 0
}
Expand Down
8 changes: 2 additions & 6 deletions packages/component/src/Styles/StyleSet/SendBoxTextBox.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {
primaryFont
} from '../Fonts';

export default function createSendBoxTextBoxStyle({
paddingRegular,
primaryFont,
sendBoxTextColor
}) {
return {
...primaryFont,

alignItems: 'center',
fontFamily: primaryFont,

'& > input': {
border: 0,
Expand Down
10 changes: 4 additions & 6 deletions packages/component/src/Styles/StyleSet/SendStatus.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {
primarySmallFont
} from '../Fonts';

export default function createSendStatusStyle({
accent,
fontSizeSmall,
primaryFont,
timestampColor
}) {
return {
...primarySmallFont,

color: timestampColor,
fontFamily: primaryFont,
fontSize: fontSizeSmall,
paddingTop: 5,

'& > button': {
Expand Down
6 changes: 2 additions & 4 deletions packages/component/src/Styles/StyleSet/SuggestedAction.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { primaryFont } from '../Fonts';

export default function createSuggestedActionStyle({
paddingRegular,
paddingWide,
primaryFont,
suggestedActionBackground,
suggestedActionBorder,
suggestedActionBorderRadius,
Expand All @@ -19,8 +18,7 @@ export default function createSuggestedActionStyle({
paddingTop: paddingRegular,

'& > button': {
...primaryFont,

fontFamily: primaryFont,
fontSize: 'inherit',
height: suggestedActionHeight,
paddingLeft: paddingWide,
Expand Down
7 changes: 2 additions & 5 deletions packages/component/src/Styles/StyleSet/TextContent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
primaryFont
} from '../Fonts';

export default function ({
bubbleMinHeight,
primaryFont,
paddingRegular
}) {
return {
...primaryFont,
fontFamily: primaryFont,
margin: 0,
minHeight: bubbleMinHeight - paddingRegular * 2,
padding: paddingRegular,
Expand Down
12 changes: 5 additions & 7 deletions packages/component/src/Styles/StyleSet/Timestamp.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
primarySmallFont
} from '../Fonts';

export default function createTimestampStyle({
timestampColor
timestampColor,
primaryFont,
fontSizeSmall
}) {
return {
...primarySmallFont,

color: timestampColor,
fontFamily: primaryFont,
fontSize: fontSizeSmall,
paddingTop: 5
};
}
98 changes: 17 additions & 81 deletions packages/component/src/Styles/adaptiveCardHostConfig.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,35 @@
import { HostConfig } from 'adaptivecards';
import defaultStyleSetOptions from './defaultStyleSetOptions';
import { primaryFont } from './Fonts';

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

export default ({ accent } = defaultStyleSetOptions) => new HostConfig({
export default ({
accent,
bubbleTextColor,
primaryFont,
subtle
} = defaultStyleSetOptions) => new HostConfig({
containerStyles: {
default: {
foregroundColors: {
default: {
default: bubbleTextColor,
subtle: subtle
},
accent: {
default: accent,
subtle: accent
}
}
},
emphasis: {
default: {
default: bubbleTextColor,
subtle: subtle
}
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compulim I'd like your opinion on this.

I made these changes based on the themes in Emulator. I think that allowing users to override the host config handles the extreme case of needing to fully customize the adaptive cards config. This change only passes a few things from the style options through.

Let me know what you think. We could extend this and add more options to styleOptions, but I thought that would not be necessary since the override already exists.


supportsInteractivity: true,
// spacing: {
// default: 8,
// extraLarge: 32,
// large: 24,
// medium: 16,
// padding: 8,
// small: 4
// },
// separator: {
// lineThickness: 1,
// lineColor: '#cccccc'
// },
fontFamily: primaryFont.fontFamily,
// fontSizes: {
// small: 12,
// default: 13,
// medium: 15,
// large: 17,
// extraLarge: 19
// },
// "fontWeights": {
// "lighter": 200,
// "default": 400,
// "bolder": 700
// },
// "containerStyles": {
// "default": {
// "backgroundColor": "#00000000",
// "foregroundColors": {
// "default": {
// "default": "#000000",
// "subtle": "#808c95"
// },
// "accent": {
// "default": "#2e89fc",
// "subtle": "#802E8901"
// },
// "attention": {
// "default": "#ffd800",
// "subtle": "#CCFFD800"
// },
// "good": {
// "default": "#00ff00",
// "subtle": "#CC00FF00"
// },
// "warning": {
// "default": "#ff0000",
// "subtle": "#CCFF0000"
// }
// }
// },
// "emphasis": {
// "backgroundColor": "#08000000",
// "foregroundColors": {
// "default": {
// "default": "#333333",
// "subtle": "#EE333333"
// },
// "accent": {
// "default": "#2e89fc",
// "subtle": "#882E89FC"
// },
// "attention": {
// "default": "#cc3300",
// "subtle": "#DDCC3300"
// },
// "good": {
// "default": "#54a254",
// "subtle": "#DD54A254"
// },
// "warning": {
// "default": "#e69500",
// "subtle": "#DDE69500"
// }
// }
// }
// },
fontFamily: primaryFont,
imageSizes: {
small: 40,
medium: 80,
Expand Down
10 changes: 9 additions & 1 deletion packages/component/src/Styles/defaultStyleSetOptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// TODO: [P4] Rename styleSetOptions to styleOptions
function fontFamily(fonts) {
return fonts.map(font => `'${ font }'`).join(', ');
}

const DEFAULT_ACCENT = '#0063B1';
const DEFAULT_SUBTLE = '#767676'; // With contrast 4.5:1 to white

Expand All @@ -10,6 +13,11 @@ const DEFAULT_OPTIONS = {
paddingWide: 20,
subtle: DEFAULT_SUBTLE,

// fonts
primaryFont: fontFamily(['Calibri', 'Helvetica Neue', 'Arial', 'sans-serif']),
monospaceFont: fontFamily(['Consolas', 'Courier New', 'monospace']),
fontSizeSmall: '80%',

// Avatar
avatarSize: 40,
botAvatarImage: '',
Expand Down