-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix emoji verification responsive layout #31899
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
76e5bb5
Extract SasEmoji to shared-components
t3chguy 1466132
Add baseline screenshots
t3chguy 8ef6613
Update tests
t3chguy a11f2bf
Fix e2e test
t3chguy e8a1fb7
Add SasEmoji snapshot test
t3chguy bc901a4
Add figma link
t3chguy b33465c
Improve doc
t3chguy b0d6813
Add new dir to crypto-web-reviewers codeowners as per ask
t3chguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+19.1 KB
...vis__/linux/__baselines__/crypto/SasEmoji/SasEmoji.stories.tsx/default-auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.5 KB
...__baselines__/crypto/SasEmoji/SasEmoji.stories.tsx/worst-case-albanian-auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.4 KB
...x/__baselines__/crypto/SasEmoji/SasEmoji.stories.tsx/worst-case-german-auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/shared-components/src/crypto/SasEmoji/SasEmoji.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright 2026 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| .container { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| gap: var(--cpd-space-2x); | ||
| justify-content: space-evenly; | ||
| } | ||
|
|
||
| .segment { | ||
| display: inline-block; | ||
| margin-bottom: var(--cpd-space-4x); | ||
| text-align: center; | ||
| /* Allow maximum 4 per line, accounting for 8px gap */ | ||
| min-width: calc(25% - 8px); | ||
| } | ||
|
|
||
| .emoji { | ||
| /* Use the Twemoji font for consistency with other clients */ | ||
| font-family: Twemoji, var(--cpd-font-family-sans); | ||
| font-size: var(--cpd-font-size-heading-xl); | ||
| } | ||
|
|
||
| .label { | ||
| font-weight: var(--cpd-font-weight-regular); | ||
| font-size: var(--cpd-font-size-body-lg); | ||
| color: var(--cpd-color-text-secondary); | ||
| } |
48 changes: 48 additions & 0 deletions
48
packages/shared-components/src/crypto/SasEmoji/SasEmoji.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| Copyright 2026 Element Creations Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import { type Meta, type StoryObj } from "@storybook/react-vite"; | ||
|
|
||
| import { SasEmoji } from "./SasEmoji"; | ||
|
|
||
| const meta = { | ||
| title: "Crypto/SasEmoji", | ||
| component: SasEmoji, | ||
| tags: ["autodocs"], | ||
| args: { | ||
| emoji: ["🍕", "🌽", "🚀", "🔒", "🔧", "🍓", "⌛"], | ||
| }, | ||
| parameters: { | ||
| design: { | ||
| type: "figma", | ||
| url: "https://www.figma.com/design/XLWIAB5n8yObYvU0INKPK1/Verification-by-Emoji?node-id=1-2935&t=NrV9JnuItrAyyh53-4", | ||
| }, | ||
| }, | ||
| } satisfies Meta<typeof SasEmoji>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const WorstCaseAlbanian: Story = { | ||
| globals: { | ||
| language: "sq", | ||
| }, | ||
| args: { | ||
| emoji: ["🎅", "🎅", "🎅", "🎅", "🎅", "🎅", "🎅"], | ||
| }, | ||
| }; | ||
|
|
||
| export const WorstCaseGerman: Story = { | ||
| globals: { | ||
| language: "de", | ||
| }, | ||
| args: { | ||
| emoji: ["🔧", "🔧", "🔧", "🔧", "🔧", "🔧", "🔧"], | ||
| }, | ||
| }; |
19 changes: 19 additions & 0 deletions
19
packages/shared-components/src/crypto/SasEmoji/SasEmoji.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| Copyright 2026 Element Creations Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import React from "react"; | ||
| import { describe, it, expect } from "vitest"; | ||
| import { render } from "@test-utils"; | ||
|
|
||
| import { SasEmoji } from "./SasEmoji"; | ||
|
|
||
| describe("<SasEmoji/>", () => { | ||
| it("should match snapshot", () => { | ||
| const { asFragment } = render(<SasEmoji emoji={["🦋", "🍄", "⚽", "🌏", "🦄", "🚀", "🔧"]} />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| }); |
43 changes: 43 additions & 0 deletions
43
packages/shared-components/src/crypto/SasEmoji/SasEmoji.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2026 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import React, { type JSX } from "react"; | ||
| import classNames from "classnames"; | ||
|
|
||
| import { type SasEmoji, tEmoji } from "./SasEmojiTranslate.ts"; | ||
| import styles from "./SasEmoji.module.css"; | ||
| import { useI18n } from "../../utils/i18nContext.ts"; | ||
|
|
||
| export type Props = { | ||
| /** | ||
| * The emoji to render | ||
| */ | ||
| emoji: [SasEmoji, SasEmoji, SasEmoji, SasEmoji, SasEmoji, SasEmoji, SasEmoji]; | ||
| /** | ||
| * Optional className to apply to the container | ||
| */ | ||
| className?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Renders the 7 emoji used for SAS verification. | ||
| * The component is responsive so can be rendered in any context, dialog, side panel. | ||
| */ | ||
| export function SasEmoji({ emoji, className }: Props): JSX.Element { | ||
| const { language } = useI18n(); | ||
|
|
||
| const emojiBlocks = emoji.map((emoji, i) => ( | ||
| <div className={styles.segment} key={i}> | ||
| <div className={styles.emoji} aria-hidden={true}> | ||
| {emoji} | ||
| </div> | ||
| <div className={styles.label}>{tEmoji(emoji, language)}</div> | ||
| </div> | ||
| )); | ||
|
|
||
| return <div className={classNames(styles.container, className)}>{emojiBlocks}</div>; | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
packages/shared-components/src/crypto/SasEmoji/SasEmojiTranslate.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| Copyright 2026 Element Creations Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import { describe, it, expect } from "vitest"; | ||
|
|
||
| import { tEmoji, type SasEmoji } from "./SasEmojiTranslate.ts"; | ||
|
|
||
| describe("tEmoji", () => { | ||
| it.each([ | ||
| ["🐶", "en-GB", "Dog"], | ||
| ["🐶", "en", "Dog"], | ||
| ["🐶", "de-DE", "Hund"], | ||
| ["🐶", "pt", "Cachorro"], | ||
| ["🔧", "de-DE", "Schraubenschlüssel"], | ||
| ["🎅", "sq", "Babagjyshi i Vitit të Ri"], | ||
| ] as [emoji: SasEmoji, locale: string, expectation: string][])( | ||
| "should handle locale %s", | ||
| (emoji, locale, expectation) => { | ||
| expect(tEmoji(emoji, locale)).toEqual(expectation); | ||
| }, | ||
| ); | ||
| }); |
122 changes: 122 additions & 0 deletions
122
packages/shared-components/src/crypto/SasEmoji/SasEmojiTranslate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Copyright 2026 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import SasEmojiJson from "@matrix-org/spec/sas-emoji.json"; | ||
| import { getNormalizedLanguageKeys } from "matrix-web-i18n"; | ||
|
|
||
| // Type as specified in https://spec.matrix.org/v1.17/client-server-api/#sas-method-emoji | ||
| export type SasEmoji = | ||
| | "🐶" | ||
| | "🐱" | ||
| | "🦁" | ||
| | "🐎" | ||
| | "🦄" | ||
| | "🐷" | ||
| | "🐘" | ||
| | "🐰" | ||
| | "🐼" | ||
| | "🐓" | ||
| | "🐧" | ||
| | "🐢" | ||
| | "🐟" | ||
| | "🐙" | ||
| | "🦋" | ||
| | "🌷" | ||
| | "🌳" | ||
| | "🌵" | ||
| | "🍄" | ||
| | "🌏" | ||
| | "🌙" | ||
| | "☁" | ||
| | "🔥" | ||
| | "🍌" | ||
| | "🍎" | ||
| | "🍓" | ||
| | "🌽" | ||
| | "🍕" | ||
| | "🎂" | ||
| | "❤" | ||
| | "😀" | ||
| | "🤖" | ||
| | "🎩" | ||
| | "👓" | ||
| | "🔧" | ||
| | "🎅" | ||
| | "👍" | ||
| | "☂" | ||
| | "⌛" | ||
| | "⏰" | ||
| | "🎁" | ||
| | "💡" | ||
| | "📕" | ||
| | "✏" | ||
| | "📎" | ||
| | "✂" | ||
| | "🔒" | ||
| | "🔑" | ||
| | "🔨" | ||
| | "☎" | ||
| | "🏁" | ||
| | "🚂" | ||
| | "🚲" | ||
| | "✈" | ||
| | "🚀" | ||
| | "🏆" | ||
| | "⚽" | ||
| | "🎸" | ||
| | "🎺" | ||
| | "🔔" | ||
| | "⚓" | ||
| | "🎧" | ||
| | "📁" | ||
| | "📌"; | ||
|
|
||
| const SasEmojiMap = new Map< | ||
| SasEmoji, | ||
| [ | ||
| description: string, | ||
| translations: { | ||
| [normalizedLanguageKey: string]: string; | ||
| }, | ||
| ] | ||
| >( | ||
| SasEmojiJson.map(({ emoji, description, translated_descriptions: translations }) => [ | ||
| emoji as SasEmoji, | ||
| [ | ||
| description, | ||
| // Normalize the translation keys | ||
| Object.keys(translations).reduce<Record<string, string>>((o, k) => { | ||
| for (const key of getNormalizedLanguageKeys(k)) { | ||
| o[key] = translations[k as keyof typeof translations]!; | ||
| } | ||
| return o; | ||
| }, {}), | ||
| ], | ||
| ]), | ||
| ); | ||
|
|
||
| /** | ||
| * Translate given SAS emoji into the target locale | ||
| * @param emoji - the SAS emoji to translate | ||
| * @param locale - the BCP 47 locale to translate to, will fall back to English as the base locale for Matrix SAS Emoji. | ||
| */ | ||
| export function tEmoji(emoji: SasEmoji, locale: string): string { | ||
| const mapping = SasEmojiMap.get(emoji); | ||
| if (!mapping) { | ||
| throw new Error(`Emoji mapping not found for emoji ${emoji}`); | ||
| } | ||
|
|
||
| const [description, translations] = mapping; | ||
|
|
||
| for (const key of getNormalizedLanguageKeys(locale)) { | ||
| if (translations[key]) { | ||
| return translations[key]; | ||
| } | ||
| } | ||
|
|
||
| return description; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.