Skip to content

Commit 70c5452

Browse files
committed
CSS Modules: migrate ActivityFeedback components
1 parent 550befa commit 70c5452

File tree

3 files changed

+110
-26
lines changed

3 files changed

+110
-26
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
:global(.webchat) .thumb-button {
2+
align-items: center;
3+
border-radius: 2px;
4+
box-sizing: content-box;
5+
display: grid;
6+
grid-template-areas: 'main';
7+
height: 16px;
8+
width: 16px;
9+
10+
.thumb-button__input {
11+
appearance: none;
12+
background: transparent;
13+
border: 0;
14+
grid-area: main;
15+
height: 16px;
16+
margin: 0;
17+
opacity: 0;
18+
padding: 0;
19+
width: 16px;
20+
21+
&:active {
22+
background: #edebe9;
23+
}
24+
}
25+
26+
&:has(.thumb-button__input:focus-visible) {
27+
outline: solid 1px #605e5c; /* <input> has opacity of 0, we need to set the outline in the container. */
28+
}
29+
30+
.thumb-button__image {
31+
color: var(--webchat__color--accent);
32+
grid-area: main;
33+
justify-self: center; /* Unsure why "justifyContent" doesn't work. */
34+
pointer-events: none;
35+
visibility: hidden;
36+
width: 14px;
37+
38+
&.thumb-button__image--is-stroked {
39+
visibility: unset;
40+
}
41+
}
42+
43+
&:has(.thumb-button__input:is(:not([aria-disabled='true']):hover, :checked, [aria-pressed='true'])) {
44+
.thumb-button__image {
45+
&.thumb-button__image--is-stroked {
46+
visibility: hidden;
47+
}
48+
49+
&.thumb-button__image--is-filled {
50+
visibility: unset;
51+
}
52+
}
53+
}
54+
55+
&.thumb-button--large {
56+
border: 1px solid transparent;
57+
border-radius: 4px;
58+
height: 30px;
59+
width: 30px;
60+
61+
.thumb-button__input {
62+
background: currentColor;
63+
height: 30px;
64+
width: 30px;
65+
}
66+
67+
.thumb-button__image {
68+
color: currentColor;
69+
font-size: 20px;
70+
height: 1em;
71+
width: 1em;
72+
}
73+
74+
&:has(.thumb-button__input:is(:hover, :active, :checked, [aria-pressed='true'])) .thumb-button__image {
75+
color: var(--webchat__color--accent);
76+
}
77+
78+
&:has(.thumb-button__input[aria-disabled='true']) .thumb-button__image {
79+
color: var(--webchat__color--subtle);
80+
}
81+
82+
&.thumb-button--has-submitted:has(.thumb-button__input:not(:checked):not([aria-pressed='true']))
83+
.thumb-button__tooltip {
84+
display: none;
85+
}
86+
87+
&.thumb-button--has-submitted .thumb-button__tooltip {
88+
--webchat__tooltip-anchor-inline-start: 20%;
89+
}
90+
}
91+
}

packages/component/src/ActivityFeedback/private/ThumbButton.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
2+
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
23
import { hooks } from 'botframework-webchat-api';
3-
import classNames from 'classnames';
4+
import cx from 'classnames';
45
import React, { forwardRef, memo, useCallback, useMemo, type ForwardedRef, type KeyboardEventHandler } from 'react';
56
import { useRefFrom } from 'use-ref-from';
67
import { boolean, function_, literal, object, optional, pipe, readonly, string, union, type InferInput } from 'valibot';
78

8-
import useStyleSet from '../../hooks/useStyleSet';
99
import testIds from '../../testIds';
1010
import { Tooltip } from '../../Tooltip';
1111
import ThumbButtonImage from './ThumbButton.Image';
1212

13+
import styles from './ThumbButton.module.css';
14+
1315
const { useLocalizer } = hooks;
1416

1517
const thumbButtonPropsSchema = pipe(
@@ -36,9 +38,9 @@ function ThumbButton(props: ThumbButtonProps, ref: ForwardedRef<HTMLInputElement
3638
props
3739
);
3840

39-
const [{ thumbButton }] = useStyleSet();
4041
const localize = useLocalizer();
4142
const onClickRef = useRefFrom(onClick);
43+
const classNames = useStyles(styles);
4244

4345
const buttonTitle = useMemo(
4446
() => title ?? localize(direction === 'down' ? 'VOTE_DISLIKE_ALT' : 'VOTE_LIKE_ALT'),
@@ -54,25 +56,19 @@ function ThumbButton(props: ThumbButtonProps, ref: ForwardedRef<HTMLInputElement
5456

5557
return (
5658
<div
57-
className={classNames(
58-
'webchat__thumb-button',
59+
className={cx(
60+
classNames['thumb-button'],
5961
{
60-
'webchat__thumb-button--large': size === 'large',
61-
'webchat__thumb-button--has-submitted': submitted
62+
[classNames['thumb-button--large']]: size === 'large',
63+
[classNames['thumb-button--has-submitted']]: submitted
6264
},
63-
className,
64-
thumbButton + ''
65+
className
6566
)}
6667
>
6768
<input
6869
aria-disabled={disabled ? 'true' : undefined}
6970
aria-label={buttonTitle}
70-
className={classNames(
71-
'webchat__thumb-button__input',
72-
{ 'webchat__thumb-button__input--is-pressed': pressed },
73-
className,
74-
thumbButton + ''
75-
)}
71+
className={cx(classNames['thumb-button__input'], className)}
7672
data-testid={testIds.feedbackButton}
7773
name={name}
7874
onKeyDown={handleKeyDown}
@@ -90,19 +86,15 @@ function ThumbButton(props: ThumbButtonProps, ref: ForwardedRef<HTMLInputElement
9086
})}
9187
/>
9288
<ThumbButtonImage
93-
className={classNames('webchat__thumb-button__image', 'webchat__thumb-button__image--is-stroked', {
94-
'webchat__thumb-button__image--is-down': direction === 'down'
95-
})}
89+
className={cx(classNames['thumb-button__image'], classNames['thumb-button__image--is-stroked'])}
9690
direction={direction}
9791
/>
9892
<ThumbButtonImage
99-
className={classNames('webchat__thumb-button__image', 'webchat__thumb-button__image--is-filled', {
100-
'webchat__thumb-button__image--is-down': direction === 'down'
101-
})}
93+
className={cx(classNames['thumb-button__image'], classNames['thumb-button__image--is-filled'])}
10294
direction={direction}
10395
filled={true}
10496
/>
105-
<Tooltip className="webchat__thumb-button__tooltip">{buttonTitle}</Tooltip>
97+
<Tooltip className={classNames['thumb-button__tooltip']}>{buttonTitle}</Tooltip>
10698
</div>
10799
);
108100
}

packages/fluent-theme/src/components/theme/Theme.module.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,17 @@
658658
}
659659

660660
/* Feedback button */
661-
:global(.webchat-fluent).theme :global(.webchat__thumb-button) {
662-
:global(.webchat__thumb-button__image) {
661+
:global(.webchat-fluent).theme :global(.thumb-button),
662+
:global(.webchat-fluent).theme :global(.thumb-button.thumb-button--large) {
663+
:global(.thumb-button__image) {
663664
color: var(--webchat-colorNeutralForeground1);
664665
}
665666

666-
&:has(:global(.webchat__thumb-button__input):focus-visible) {
667+
&:has(:global(.thumb-button__input):focus-visible) {
667668
outline: var(--webchat-strokeWidthThick) solid var(--webchat-colorStrokeFocus2);
668669
}
669670

670-
&:has(:global(.webchat__thumb-button__input)[aria-disabled='true']) :global(.webchat__thumb-button__image) {
671+
&:has(:global(.thumb-button__input)[aria-disabled='true']) :global(.thumb-button__image) {
671672
color: var(--webchat-colorNeutralForegroundDisabled);
672673
}
673674
}

0 commit comments

Comments
 (0)