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

feat: convert Emoji #861

Merged
merged 6 commits into from
Jul 12, 2021
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
5 changes: 5 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace NodeJS {
interface Process {
browser: boolean
}
}
1 change: 1 addition & 0 deletions packages/Emoji/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/*
!/dist/*.js
!/dist/*.d.ts
File renamed without changes.
32 changes: 15 additions & 17 deletions packages/Emoji/index.js → packages/Emoji/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import React, { useMemo } from 'react'
import { bool, number, string } from 'prop-types'
import { Box } from '@welcome-ui/box'
import Bowser from 'bowser'
import { WuiProps } from '@welcome-ui/system'

const EMOJI_PATH = 'https://cdn.welcome-ui.com/emojis/'

// Apple by default for SSR
const IS_APPLE_OS =
!process.browser || Bowser.parse(window.navigator.userAgent).platform.vendor === 'Apple'

export function Emoji({
export interface EmojiProps extends React.HTMLAttributes<HTMLImageElement> {
emoji?: string
height?: number
size?: number
useAppleEmoji?: boolean
width?: number
}

export const Emoji: React.FC<EmojiProps & WuiProps> = ({
emoji,
useAppleEmoji = IS_APPLE_OS,
height = 24,
size,
useAppleEmoji = IS_APPLE_OS,
width = 24,
height = 24,
...rest
}) {
}) => {
const isUrl = useMemo(() => {
try {
new URL(emoji)
Expand All @@ -39,15 +47,5 @@ export function Emoji({
)
}

Emoji.propTypes = {
/** The slack emoji, e.g: :sweat-smile: or a URL */
emoji: string,
height: number,
/** Helper to prevent to set width & height */
size: number,
/** Needed for SSR, it defaults to true on the server */
useAppleEmoji: bool,
width: number
}

export const getEmojiName = alias => alias?.replace?.(/:/g, '')
// eslint-disable-next-line prettier/prettier
export const getEmojiName = (alias: string): string => alias?.replace?.(/:/g, '')
1 change: 1 addition & 0 deletions packages/Emoji/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Customizable design system with react • styled-components • styled-system and reakit.",
"main": "dist/emoji.cjs.js",
"module": "dist/emoji.es.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/Emoji/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { getRollupConfig } from '../../rollup.config.js'

export default getRollupConfig({ pwd: __dirname })
export default getRollupConfig({ pwd: __dirname, ts: true })
2 changes: 0 additions & 2 deletions packages/Utils/use-isomorphic-layout-effect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useEffect, useLayoutEffect } from 'react'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export const useIsomorphicLayoutEffect = process.browser ? useLayoutEffect : useEffect
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"sourceMap": false,
"declaration": true
},
"include": ["packages/*", "packages/**/*", "icons/*", "icons/**/*", "./styled.d.ts"],
"include": ["packages/*", "packages/**/*", "icons/*", "icons/**/*", "./styled.d.ts", "./global.d.ts"],
"exclude": ["node_modules", "dist", "**/*.test.tsx"]
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14551,7 +14551,7 @@ prettier-linter-helpers@^1.0.0:
prettier@=1.18.2:
version "1.18.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"
integrity "sha1-aCPnxZAAF7S9Os9G/prEtNe9qeo= sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw=="
integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==

pretty-format@^24.9.0:
version "24.9.0"
Expand Down