Skip to content

Commit 72dcb49

Browse files
authored
refactor: Migrate reaction button component to type script (#266)
1 parent 9931308 commit 72dcb49

File tree

6 files changed

+49
-69
lines changed

6 files changed

+49
-69
lines changed

exports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default {
136136
'ui/QuoteMessage': 'src/ui/QuoteMessage/index.tsx',
137137
'ui/QuoteMessageInput': 'src/ui/QuoteMessageInput/index.tsx',
138138
'ui/ReactionBadge': 'src/ui/ReactionBadge/index.tsx',
139-
'ui/ReactionButton': 'src/ui/ReactionButton/index.jsx',
139+
'ui/ReactionButton': 'src/ui/ReactionButton/index.tsx',
140140
'ui/SortByRow': 'src/ui/SortByRow/index.tsx',
141141
'ui/TextButton': 'src/ui/TextButton/index.jsx',
142142
'ui/TextMessageItemBody': 'src/ui/TextMessageItemBody/index.tsx',

src/ui/ReactionButton/__tests__/__snapshots__/ReactionButton.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ exports[`ReactionButton should do a snapshot test of the ReactionButton DOM 1`]
88
role="button"
99
style={
1010
Object {
11-
"height": "34px",
12-
"width": "34px",
11+
"height": "36px",
12+
"width": "36px",
1313
}
1414
}
1515
tabIndex={0}

src/ui/ReactionButton/index.jsx

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/ui/ReactionButton/index.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
border-radius: 8px;
55
display: inline-block;
66
border: solid 1px transparent;
7+
box-sizing: border-box;
78
cursor: pointer;
89

910
&:hover {
@@ -22,6 +23,7 @@
2223
cursor: pointer;
2324
border-radius: 8px;
2425
display: inline-block;
26+
box-sizing: border-box;
2527
@include themed() {
2628
border: solid 1px t(primary--1-4);
2729
background-color: t(primary--1-4);

src/ui/ReactionButton/index.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { KeyboardEvent, MouseEvent, ReactElement, RefObject } from 'react';
2+
3+
import './index.scss';
4+
5+
export interface ReactionButtonProps {
6+
children: ReactElement;
7+
className?: string | Array<string>;
8+
width?: string | number;
9+
height?: string | number;
10+
selected?: boolean;
11+
onClick?: (e: MouseEvent<HTMLDivElement> | KeyboardEvent<HTMLDivElement>) => void;
12+
}
13+
const ReactionButton = React.forwardRef((props: ReactionButtonProps, ref: RefObject<HTMLDivElement>): ReactElement => {
14+
const {
15+
className,
16+
width,
17+
height,
18+
selected,
19+
onClick,
20+
children,
21+
} = props;
22+
23+
return (
24+
<div
25+
className={[
26+
...(Array.isArray(className) ? className : [className]),
27+
`sendbird-reaction-button${selected ? '--selected' : ''}`,
28+
].join(' ')}
29+
ref={ref}
30+
role="button"
31+
style={{ width, height }}
32+
onClick={(e) => onClick(e)}
33+
onKeyDown={(e) => onClick(e)}
34+
tabIndex={0}
35+
>
36+
<div className="sendbird-reaction-button__inner">
37+
{children}
38+
</div>
39+
</div>
40+
);
41+
});
42+
43+
export default ReactionButton;

src/ui/ReactionButton/stories/ReactionButton.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import ReactionButton from '../index.jsx';
2+
import ReactionButton from '../index';
33
import Icon, { IconTypes } from '../../Icon';
44

55
const description = `

0 commit comments

Comments
 (0)