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

fix(fuselage, message-parser): Remove list components and update list grammar #724

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/fuselage/src/components/Message/MessageOrderedList.tsx

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions packages/fuselage/src/components/Message/MessageUnorderedList.tsx

This file was deleted.

This file was deleted.

32 changes: 10 additions & 22 deletions packages/fuselage/src/components/Message/Messages.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,11 @@ export const MessageUnorderedList = () => (
</Message.Header>
<Message.Body>
Unordered list:
<Message.UnorderedList>
<Message.UnorderedListItem>
Ut enim ad minim
</Message.UnorderedListItem>
<Message.UnorderedListItem>
Incididunt ut labore
</Message.UnorderedListItem>
<Message.UnorderedListItem>
Labore et dolore
</Message.UnorderedListItem>
</Message.UnorderedList>
<ul>
<li>Ut enim ad minim</li>
<li>Incididunt ut labore</li>
<li>Labore et dolore</li>
</ul>
</Message.Body>
<MessageReactions>
<MessageReactions.Reaction counter={1} />
Expand Down Expand Up @@ -487,17 +481,11 @@ export const MessageOrderedList = () => (
</Message.Header>
<Message.Body>
Ordered list:
<Message.OrderedList>
<Message.OrderedListItem value={1}>
Ut enim ad minim
</Message.OrderedListItem>
<Message.OrderedListItem value={2}>
Incididunt ut labore
</Message.OrderedListItem>
<Message.OrderedListItem value={3}>
Labore et dolore
</Message.OrderedListItem>
</Message.OrderedList>
<ol>
<li value={1}>Ut enim ad minim</li>
<li value={2}>Incididunt ut labore</li>
<li value={6}>Labore et dolore</li>
</ol>
</Message.Body>
<MessageReactions>
<MessageReactions.Reaction counter={1} />
Expand Down
36 changes: 15 additions & 21 deletions packages/fuselage/src/components/Message/Messages.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -207,36 +207,30 @@ $message-background-color-highlight: functions.theme(
}
}

&-unordered-list {
padding-top: lengths.padding(4);
& ul,
ol {
margin: 0;
padding-block-start: lengths.padding(4);
padding-block-end: 0;
padding-inline: 0;

list-style: none;
}

&__item {
&::before {
padding: 0 lengths.padding(8);
& ul li::before {
padding: 0 lengths.padding(8);

content: '•';
content: '•';

font-weight: bold;
}
}
font-weight: bold;
}

&-ordered-list {
padding-top: lengths.padding(4);
& ol li::before {
padding: 0 lengths.padding(8);

list-style: none;
content: attr(value) '.';

&__item {
&::before {
padding: 0 lengths.padding(8);

content: attr(value) '.';

font-weight: bold;
}
}
font-weight: bold;
}

&__emoji {
Expand Down
12 changes: 0 additions & 12 deletions packages/fuselage/src/components/Message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import { MessageHeader } from './MessageHeader';
import { MessageLeftContainer } from './MessageLeftContainer';
import MessageMetrics from './MessageMetrics';
import { MessageName } from './MessageName';
import { MessageOrderedList } from './MessageOrderedList';
import { MessageOrderedListItem } from './MessageOrderedListItem';
import { MessageRole } from './MessageRole';
import { MessageRoles } from './MessageRoles';
import { MessageTimestamp } from './MessageTimestamp';
import MessageToolbox from './MessageToolbox';
import { MessageUnorderedList } from './MessageUnorderedList';
import { MessageUnorderedListItem } from './MessageUnorderedListItem';
import { MessageUsername } from './MessageUsername';

export * from './MessageDivider';
Expand All @@ -38,10 +34,6 @@ export * from './MessageRoles';
export * from './MessageTimestamp';
export * from './MessageUsername';
export * from './MessageEmoji';
export * from './MessageUnorderedList';
export * from './MessageUnorderedListItem';
export * from './MessageOrderedList';
export * from './MessageOrderedListItem';

export default Object.assign(Message, {
Metrics: MessageMetrics,
Expand All @@ -52,10 +44,6 @@ export default Object.assign(Message, {
Header: MessageHeader,
Body: MessageBody,
Block: MessageBlock,
OrderedList: MessageOrderedList,
OrderedListItem: MessageOrderedListItem,
UnorderedList: MessageUnorderedList,
UnorderedListItem: MessageUnorderedListItem,
Timestamp: MessageTimestamp,
Name: MessageName,
Username: MessageUsername,
Expand Down
9 changes: 2 additions & 7 deletions packages/message-parser/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Blockquote = {

export type OrderedList = {
type: 'ORDERED_LIST';
value: OrderedListItem[];
value: ListItem[];
};

export type UnorderedList = {
Expand All @@ -16,11 +16,7 @@ export type UnorderedList = {
export type ListItem = {
type: 'LIST_ITEM';
value: Inlines[];
};

export type OrderedListItem = {
type: 'ORDERED_LIST_ITEM';
value: { digit: string; text: Inlines[] };
number?: number;
};

export type Tasks = {
Expand Down Expand Up @@ -160,7 +156,6 @@ export type Types = {
TASK: Task;
UNORDERED_LIST: UnorderedList;
ORDERED_LIST: OrderedList;
ORDERED_LIST_ITEM: OrderedListItem;
LIST_ITEM: ListItem;
IMAGE: Image;
LINE_BREAK: LineBreak;
Expand Down
8 changes: 3 additions & 5 deletions packages/message-parser/src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
task,
orderedList,
listItem,
orderedListItem,
unorderedList,
lineBreak,
} = require('./utils');
Expand Down Expand Up @@ -275,10 +274,10 @@ UnorderedList_ = lists:UnorderedListItem_+ { return unorderedList(lists); }

UnorderedList__ = lists:UnorderedListItem__+ { return unorderedList(lists); }

UnorderedListItem_ = "- " text:Inline { return listItem(text, true); }
UnorderedListItem_ = "- " text:Inline { return listItem(text); }

UnorderedListItem__
= "* " text:UnorderedListItem__Inline { return listItem(text, true); }
= "* " text:UnorderedListItem__Inline { return listItem(text); }

UnorderedListItem__Inline
= value:(
Expand All @@ -300,8 +299,7 @@ UnorderedListItem__Inline

OrderedList = lists:OrderedListItem+ { return orderedList(lists); }

OrderedListItem
= d:digits "\x2E " text:Inline { return orderedListItem(d, text); }
OrderedListItem = d:digits "\x2E " text:Inline { return listItem(text, d); }

Codetype = t:[a-zA-Z0-9 \_\-.]+ { return t.join(''); }

Expand Down
12 changes: 6 additions & 6 deletions packages/message-parser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
Paragraph,
Types,
Task,
ListItem,
Inlines,
} from './definitions';

Expand Down Expand Up @@ -85,12 +86,11 @@ export const orderedList = generate('ORDERED_LIST');

export const unorderedList = generate('UNORDERED_LIST');

export const listItem = generate('LIST_ITEM');

export const orderedListItem = (() => {
const fn = generate('ORDERED_LIST_ITEM');
return (digit: string, text: Inlines[]) => fn({ digit, text });
})();
export const listItem = (text: Inlines[], number?: string): ListItem => ({
type: 'LIST_ITEM',
value: text,
...(number && { number: Number(number) }),
});

export const mentionUser = (() => {
const fn = generate('MENTION_USER');
Expand Down
12 changes: 6 additions & 6 deletions packages/message-parser/tests/orderedList.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parser } from '../src';
import { bold, plain, orderedList, orderedListItem } from '../src/utils';
import { bold, plain, orderedList, listItem } from '../src/utils';

test.each([
[
Expand All @@ -12,11 +12,11 @@ test.each([
`.trim(),
[
orderedList([
orderedListItem('7', [plain('First item')]),
orderedListItem('2', [plain('Second item')]),
orderedListItem('8', [plain('Third item')]),
orderedListItem('4', [bold([plain('Fourth item')])]),
orderedListItem('15', [bold([plain('Fifteenth item')])]),
listItem([plain('First item')], '7'),
listItem([plain('Second item')], '2'),
listItem([plain('Third item')], '8'),
listItem([bold([plain('Fourth item')])], '4'),
listItem([bold([plain('Fifteenth item')])], '15'),
]),
],
],
Expand Down