Skip to content

Set --epr-sheet-x/--epr-sheet-y CSS variables #323

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const keys = {
EMOJI_PROPERTY_SKIN_VARIATIONS: 'v',
EMOJI_PROPERTY_GROUP: 'g',
EMOJI_PROPERTY_ADDED_IN: 'a',
EMOJI_PROPERTY_X: 'x',
EMOJI_PROPERTY_Y: 'y',
GROUP_NAME_PEOPLE: 'smileys_people',
GROUP_NAME_NATURE: 'animals_nature',
GROUP_NAME_FOOD: 'food_drink',
Expand Down Expand Up @@ -50,6 +52,8 @@ const cleanEmoji = (emoji) => {
].sort((a, b) => a.length - b.length);
emoji[keys.EMOJI_PROPERTY_UNIFIED] = emoji.unified;
emoji[keys.EMOJI_PROPERTY_ADDED_IN] = emoji.added_in;
emoji[keys.EMOJI_PROPERTY_X] = emoji.sheet_x;
emoji[keys.EMOJI_PROPERTY_Y] = emoji.sheet_y;

if (emoji.skin_variations) {
emoji[keys.EMOJI_PROPERTY_SKIN_VARIATIONS] = Object.values(
Expand All @@ -63,6 +67,8 @@ const cleanEmoji = (emoji) => {
keys.EMOJI_PROPERTY_SKIN_VARIATIONS,
keys.EMOJI_PROPERTY_SKIN_VARIATIONS,
keys.EMOJI_PROPERTY_ADDED_IN,
keys.EMOJI_PROPERTY_X,
keys.EMOJI_PROPERTY_Y,
]);
};

Expand Down
6 changes: 6 additions & 0 deletions src/components/emoji/Emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ function EmojiImg({
return (
<img
src={getEmojiUrl(unified, emojiStyle)}
ref={(elem) => {
if (elem) {
elem.style.setProperty('--epr-sheet-x', emoji.x.toString());
elem.style.setProperty('--epr-sheet-y', emoji.y.toString());
}
}}
alt={emojiName(emoji)}
className={clsx(ClassNames.external, 'epr-emoji-img')}
loading={lazyLoad ? 'lazy' : 'eager'}
Expand Down
2 changes: 1 addition & 1 deletion src/data/emojis.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/dataUtils/DataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type DataEmoji = {
u: string;
v?: string[];
a: string;
x: number;
y: number;
};
export type DataEmojis = DataEmoji[];

Expand Down
12 changes: 11 additions & 1 deletion src/dataUtils/emojiSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ enum EmojiProperties {
name = 'n',
unified = 'u',
variations = 'v',
added_in = 'a'
added_in = 'a',
sheet_x = 'x',
sheet_y = 'y',
}

export function emojiNames(emoji: DataEmoji): string[] {
Expand All @@ -23,6 +25,14 @@ export function addedIn(emoji: DataEmoji): number {
return parseFloat(emoji[EmojiProperties.added_in]);
}

export function sheetX(emoji: DataEmoji): number {
return emoji[EmojiProperties.sheet_x];
}

export function sheetY(emoji: DataEmoji): number {
return emoji[EmojiProperties.sheet_y];
}

export function emojiName(emoji?: DataEmoji): string {
if (!emoji) {
return '';
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useMouseDownHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
emojiHasVariations,
emojiNames,
emojiUnified,
sheetX,
sheetY,
} from '../dataUtils/emojiSelectors';
import { parseNativeEmoji } from '../dataUtils/parseNativeEmoji';
import { setsuggested } from '../dataUtils/suggested';
Expand Down Expand Up @@ -168,6 +170,8 @@ function emojiClickOutput(
return getEmojiUrl(unified, emojiStyle);
},
names: emojiNames(emoji),
sheetX: sheetX(emoji),
sheetY: sheetY(emoji),
unified,
unifiedWithoutSkinTone: emojiUnified(emoji),
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/exposedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export type EmojiClickData = {
activeSkinTone: SkinTones;
unified: string;
unifiedWithoutSkinTone: string;
sheetX: number;
sheetY: number;
emoji: string;
names: string[];
getImageUrl: (emojiStyle: EmojiStyle) => string;
Expand Down