Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd committed Apr 24, 2024
1 parent 4aba3b5 commit 4251c72
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions sparkle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sparkle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dust-tt/sparkle",
"version": "0.2.145",
"version": "0.2.146",
"scripts": {
"build": "rm -rf dist && rollup -c",
"build:with-tw-base": "rollup -c --environment INCLUDE_TW_BASE:true",
Expand Down
8 changes: 5 additions & 3 deletions sparkle/src/components/EmojiPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { EmojiMartData, Skin } from "@emoji-mart/data";
import type { EmojiMartData } from "@emoji-mart/data";
import Picker from "@emoji-mart/react";
import React from "react";

import { EmojiSkinType } from "@sparkle/lib/avatar/types";

interface EmojiPickerProps {
data: EmojiMartData;
onEmojiSelect: (emoji: Skin) => void;
data?: EmojiMartData;
onEmojiSelect: (emoji: EmojiSkinType) => void;
previewPosition?: "none";
theme: "dark" | "light";
}
Expand Down
7 changes: 7 additions & 0 deletions sparkle/src/lib/avatar/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type {
Emoji,
EmojiMartData as EmojiData,
Skin as EmojiSkin,
} from "@emoji-mart/data";

export type EmojiSkinType = Pick<Emoji, "id" | "name" | "keywords"> & {
native: string;
shortcodes: string;
unified: string;
};

export { EmojiData, EmojiSkin };
16 changes: 9 additions & 7 deletions sparkle/src/lib/avatar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { EmojiData } from "@sparkle/lib/avatar/types";

const EMOJI_URL_REGEXP = /\/emojis\/bg-([^/]*)\/([^/]*)\/([^/.]*)/;

type backgroundColorType = `bg-${string}`;

/**
* This helper extracts emojis and background color from a Dust url.
* URL structure is defined as such:
Expand All @@ -28,27 +30,27 @@ export function getEmojiAndBackgroundFromUrl(url: string) {
return null;
}

const prefixedBackgroundColor: backgroundColorType = `bg-${backgroundColor}`;

return {
backgroundColor,
backgroundColor: prefixedBackgroundColor,
id,
unified,
native: skinEmoji.native,
skinEmoji: skinEmoji.native,
};
}

return null;
}

type bgColorType = `bg-${string}`;

export function createEmojiAndBackgroundUrlSuffix({
bgColor,
backgroundColor,
id,
unified,
}: {
bgColor: bgColorType;
backgroundColor: backgroundColorType;
id: string;
unified: string;
}) {
return `/emojis/${bgColor}/${id}/${unified}`;
return `/emojis/${backgroundColor}/${id}/${unified}`;
}
7 changes: 7 additions & 0 deletions sparkle/src/stories/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export const AvatarExample = () => (
<Avatar size="xl" name="Omar Doe" />
<Avatar size="xxl" name="Omar Doe" />
</div>
<div>With emoji url</div>
<div className="s-flex s-gap-4">
<Avatar
size="xs"
visual="https://dust.tt/static/emojis/bg-cyan-100/lotus/1fab7"
/>
</div>
<div>With emoji</div>
<div className="s-flex s-gap-4">
<Avatar size="xs" emoji="❤️" backgroundColor="s-bg-red-100" />
Expand Down

0 comments on commit 4251c72

Please sign in to comment.