Skip to content

Commit cdaa358

Browse files
authored
fix: ui-kit margins warnings and unique ids (#130)
1 parent 90c5301 commit cdaa358

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

packages/fuselage-ui-kit/src/Actions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const Actions = ({ blockId, appId, elements, parser }) => {
2727
const renderedElements = (showMoreVisible
2828
? elements.slice(0, 5)
2929
: elements
30-
).map((element, i) => <Margins key={i} all={8}><Flex.Item basis={getStyle(element)}>{parser.renderActions({ blockId, appId, ...element }, BLOCK_CONTEXT.ACTION, parser)}</Flex.Item></Margins>);
30+
).map((element, i) => <Margins key={i} all='x8'><Flex.Item basis={getStyle(element)}>{parser.renderActions({ blockId, appId, ...element }, BLOCK_CONTEXT.ACTION, parser)}</Flex.Item></Margins>);
3131

3232
const handleShowMoreClick = () => {
3333
setShowMoreVisible(false);

packages/fuselage-ui-kit/src/Block.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import {
33
Margins,
44
} from '@rocket.chat/fuselage';
55

6-
export const Block = ({ children }) => (
7-
<Margins blockEnd={16}>{children}</Margins>
6+
export const Block = ({ children, blockEnd = 'x16' }) => (
7+
<Margins blockEnd={blockEnd}>{children}</Margins>
88
);

packages/fuselage-ui-kit/src/index.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ class TextParser extends UiKitParserText {
8989
}
9090

9191
class ButtonsParser extends UiKitParserButtons {
92-
button(element, context) {
92+
button(element, context, key) {
9393
const [{ loading }, action] = useBlockContext(element, context);
9494
return (
9595
<Button
96+
key={key}
9697
mod-mod-loading={loading}
9798
{...getStyle(element.style)}
9899
small={context === BLOCK_CONTEXT.SECTION}
@@ -119,10 +120,11 @@ class MessageParser extends UiKitParserMessage {
119120
return <Overflow loading={loading} {...element} onChange={action} parser={this}/>;
120121
}
121122

122-
button(element, context) {
123+
button(element, context, key) {
123124
const [{ loading }, action] = useBlockContext(element, context);
124125
return (
125126
<Button
127+
key={key}
126128
mod-mod-loading={loading}
127129
{...getStyle(element.style)}
128130
small
@@ -135,8 +137,8 @@ class MessageParser extends UiKitParserMessage {
135137
);
136138
}
137139

138-
divider() {
139-
return <Block><Divider /></Block>;
140+
divider(_, __, key) {
141+
return <Margins block={'x24'} key={key}> <Divider /> </Margins>;
140142
}
141143

142144
section(args, context, index) {
@@ -145,18 +147,18 @@ class MessageParser extends UiKitParserMessage {
145147
);
146148
}
147149

148-
actions(args) {
150+
actions(args, _, key) {
149151
return (
150-
<ActionsLayoutBlock {...args} parser={this} />
152+
<ActionsLayoutBlock {...args} key={key} parser={this} />
151153
);
152154
}
153155

154-
datePicker(element, context, index) {
156+
datePicker(element, context, key) {
155157
const [{ loading }, action] = useBlockContext(element, context);
156158
const { actionId, placeholder } = element;
157159
return (
158160
<InputBox
159-
key={index}
161+
key={key}
160162
mod-mod-loading={loading}
161163
id={actionId}
162164
name={actionId}
@@ -168,19 +170,19 @@ class MessageParser extends UiKitParserMessage {
168170
);
169171
}
170172

171-
image(element, context, index) {
172-
return <MessageImage key={index} element={element} context={context}/>;
173+
image(element, context, key) {
174+
return <MessageImage key={key} element={element} context={context}/>;
173175
}
174176

175-
context({ elements }, context, index) {
177+
context({ elements }, context, key) {
176178
return (
177-
<Block>
178-
<Box is='div' className='TESTE'>
179-
<Flex.Container alignItems='center' key={index}>
179+
<Block key={key}>
180+
<Box is='div'>
181+
<Flex.Container alignItems='center'>
180182
<Margins all='neg-x4'>
181183
<Box is='div'>
182184
{elements.map((element, i) => (
183-
<Margins all={4} key={i}>
185+
<Margins all='x4' key={i}>
184186
<Flex.Item>
185187
{[
186188
ELEMENT_TYPES.PLAIN_TEXT_INPUT,
@@ -204,27 +206,28 @@ class MessageParser extends UiKitParserMessage {
204206
);
205207
}
206208

207-
multiStaticSelect(element, context) {
209+
multiStaticSelect(element, context, key) {
208210
const [{ loading }, action] = useBlockContext(element, context);
209211
return (
210212
<MultiStaticSelect
211213
{...element}
214+
key={key}
212215
mod-loading={loading}
213216
onChange={action}
214217
parser={this}
215218
/>
216219
);
217220
}
218221

219-
staticSelect(element, context) {
222+
staticSelect(element, context, key) {
220223
const [{ loading }, action] = useBlockContext(element, context);
221-
return <StaticSelect {...element} mod-loading={loading} onChange={action} parser={this} />;
224+
return <StaticSelect key={key} {...element} mod-loading={loading} onChange={action} parser={this} />;
222225
}
223226

224-
selectInput(element, context) {
227+
selectInput(element, context, key) {
225228
const [{ loading }, action] = useBlockContext(element, context);
226229
return (
227-
<SelectInput onChange={action} mod-loading={loading} placeholder={element.type} disabled />
230+
<SelectInput key={key} onChange={action} mod-loading={loading} placeholder={element.type} disabled />
228231
);
229232
}
230233
}

0 commit comments

Comments
 (0)