Skip to content

Commit

Permalink
on preview change props
Browse files Browse the repository at this point in the history
  • Loading branch information
Xindi Xu committed Jul 20, 2020
1 parent d994d50 commit 48bed5c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/components/picker/nimble-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export default class NimblePicker extends React.PureComponent {
// Focus on first category anchor
this.anchors.buttons.firstChild.focus()
this.setState({ emoji: null })
this.props.onShowSkin()
return

case 'ArrowLeft':
Expand Down Expand Up @@ -824,6 +825,7 @@ export default class NimblePicker extends React.PureComponent {
title={title}
emoji={emoji}
idleEmoji={idleEmoji}
onShowSkin={this.props.onShowSkin}
showSkinTones={showSkinTones}
showPreview={showPreview}
emojiProps={{
Expand Down
89 changes: 48 additions & 41 deletions src/components/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export default class Preview extends React.PureComponent {
this.data = props.data
}

componentDidUpdate(prevProps) {
if (prevProps.emoji && !this.props.emoji) {
this.props.onShowSkin()
}
}

render() {
const {
emoji,
Expand Down Expand Up @@ -70,54 +76,55 @@ export default class Preview extends React.PureComponent {
</div>
</div>
)
} else {
return (
<div className="emoji-mart-preview">
<div className="emoji-mart-preview-emoji" aria-hidden="true">
{idleEmoji &&
idleEmoji.length &&
NimbleEmoji({
emoji: idleEmoji,
data: this.data,
...emojiProps,
})}
</div>
}

<div className="emoji-mart-preview-data" aria-hidden="true">
<span className="emoji-mart-title-label">{title}</span>
</div>
return (
<div className="emoji-mart-preview">
<div className="emoji-mart-preview-emoji" aria-hidden="true">
{idleEmoji &&
idleEmoji.length &&
NimbleEmoji({
emoji: idleEmoji,
data: this.data,
...emojiProps,
})}
</div>

{showSkinTones && (
<div
className={`emoji-mart-preview-skins${
skinsProps.skinEmoji ? ' custom' : ''
}`}
>
{skinsProps.skinEmoji ? (
<SkinsEmoji
skin={skinsProps.skin}
emojiProps={emojiProps}
data={this.data}
skinEmoji={skinsProps.skinEmoji}
i18n={i18n}
onChange={skinsProps.onChange}
/>
) : (
<SkinsDot
skin={skinsProps.skin}
i18n={i18n}
onChange={skinsProps.onChange}
/>
)}
</div>
)}
<div className="emoji-mart-preview-data" aria-hidden="true">
<span className="emoji-mart-title-label">{title}</span>
</div>
)
}

{showSkinTones && (
<div
className={`emoji-mart-preview-skins${
skinsProps.skinEmoji ? ' custom' : ''
}`}
>
{skinsProps.skinEmoji ? (
<SkinsEmoji
skin={skinsProps.skin}
emojiProps={emojiProps}
data={this.data}
skinEmoji={skinsProps.skinEmoji}
i18n={i18n}
onChange={skinsProps.onChange}
/>
) : (
<SkinsDot
skin={skinsProps.skin}
i18n={i18n}
onChange={skinsProps.onChange}
/>
)}
</div>
)}
</div>
)
}
}

Preview.propTypes = {
onShowSkin: PropTypes.func.isRequired,
showSkinTones: PropTypes.bool,
title: PropTypes.string.isRequired,
idleEmoji: PropTypes.string.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/components/skins-dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default class SkinsDot extends Skins {

case 'Tab':
e.preventDefault()
e.stopPropagation()
if (e.shiftKey) {
selectLeft()
} else {
Expand All @@ -75,6 +74,7 @@ export default class SkinsDot extends Skins {
default:
break
}
e.stopPropagation()
}

setSkinTonesRef(c) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/shared-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const PickerDefaultProps = {
onClick: () => {},
onSelect: () => {},
onSkinChange: () => {},
onShowSkin: () => {},
emojiSize: 24,
perLine: 9,
i18n: {},
Expand Down
1 change: 1 addition & 0 deletions src/utils/shared-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const PickerPropTypes = {
onClick: PropTypes.func,
onSelect: PropTypes.func,
onSkinChange: PropTypes.func,
onShowSkin: PropTypes.func,
perLine: PropTypes.number,
emojiSize: PropTypes.number,
i18n: PropTypes.object,
Expand Down

0 comments on commit 48bed5c

Please sign in to comment.