Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Add PillButton to stems
Browse files Browse the repository at this point in the history
  • Loading branch information
Saliou Diallo committed Jul 27, 2022
1 parent 49926ba commit 2add00d
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 52 deletions.
42 changes: 42 additions & 0 deletions packages/stems/src/components/PillButton/PillButton.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.button {
height: unset !important;
padding: 10px 0;
border-radius: 100px;
border: 1px solid var(--neutral-light-4);
background: var(--white);
}
.buttonText {
display: flex;
align-items: center;
text-transform: uppercase;
font-size: var(--font-xs) !important;
color: var(--neutral) !important;
letter-spacing: unset !important;
}
.button:hover {
transform: scale3d(1.01, 1.01, 1.01) !important;
border: unset !important;
}
.button:active {
transform: scale3d(0.99, 0.99, 0.99) !important;
}
.button:hover .buttonText,
.button:active .buttonText {
color: var(--white) !important;
}
.button.primary:hover,
.button.primary:hover .buttonText {
background: var(--primary) !important;
}
.button.primary:active,
.button.primary:active .buttonText {
background: var(--primary-dark-2) !important;
}
.button.secondary:hover,
.button.secondary:hover .buttonText {
background: var(--secondary-light-2) !important;
}
.button.secondary:active,
.button.secondary:active .buttonText {
background: var(--secondary) !important;
}
23 changes: 23 additions & 0 deletions packages/stems/src/components/PillButton/PillButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Story } from '@storybook/react'

import { PillButton, PillButtonProps } from './'

export default {
component: PillButton,
title: 'Components/PillButton'
}

const defaultProps: PillButtonProps = {
text: 'Pill Button'
}

const Template: Story<PillButtonProps> = (args) => {
return <PillButton {...defaultProps} {...args} />
}

// Default
export const Default = Template.bind({})

// Disabled
export const Disabled = Template.bind({})
Disabled.args = { disabled: true }
29 changes: 29 additions & 0 deletions packages/stems/src/components/PillButton/PillButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import cn from 'classnames'

import { Button, Type as ButtonType } from 'components/Button'

import styles from './PillButton.module.css'
import { PillButtonProps, Type as PillButtonType } from './types'

const TYPE_STYLE_MAP = {
[PillButtonType.PRIMARY]: styles.primary,
[PillButtonType.SECONDARY]: styles.secondary
}
export const PillButton = (props: PillButtonProps) => {
const {
text,
onClick,
type = PillButtonType.PRIMARY,
className,
textClassName
} = props
return (
<Button
className={cn(styles.button, TYPE_STYLE_MAP[type], className)}
textClassName={cn(styles.buttonText, textClassName)}
type={ButtonType.COMMON}
text={text}
onClick={onClick}
/>
)
}
2 changes: 2 additions & 0 deletions packages/stems/src/components/PillButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { PillButton } from './PillButton'
export { PillButtonProps, Type } from './types'
18 changes: 18 additions & 0 deletions packages/stems/src/components/PillButton/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HTMLAttributes } from 'react'
// import { HTMLAttributes, ReactNode } from 'react'
import * as React from 'react'

export enum Type {
PRIMARY = 'primary',
SECONDARY = 'secondary'
}

export type PillButtonProps = HTMLAttributes<HTMLButtonElement> & {
text: any
// text: ReactNode
onClick?: (event: React.MouseEvent) => void
disabled?: boolean
type?: Type
className?: string
textClassName?: string
}
5 changes: 5 additions & 0 deletions packages/stems/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export {
Size as ButtonSize
} from './components/Button'
export { IconButton, IconButtonProps } from './components/IconButton'
export {
PillButton,
PillButtonProps,
Type as PillButtonType
} from './components/PillButton'
export { Scrollbar, ScrollbarProps } from './components/Scrollbar'
export {
Modal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,13 @@
}

.sendTipButton {
height: unset !important;
margin-left: 8px;
padding: 10px 0;
border-radius: 100px;
border: 1px solid var(--neutral-light-4);
background: var(--white);
}
.sendTipButtonText {
.sendTipButtonTextContainer {
display: flex;
align-items: center;
font-weight: var(--font-bold);
font-size: var(--font-xs);
color: var(--neutral-light-4);
text-transform: uppercase;
}
.sendTipButton:hover {
transform: scale3d(1.01, 1.01, 1.01) !important;
border: unset;
}
.sendTipButton:active {
transform: scale3d(0.99, 0.99, 0.99) !important;
}
.sendTipButton:hover .sendTipButtonText,
.sendTipButton:active .sendTipButtonText {
color: var(--white);
}
.sendTipButton:active,
.sendTipButton:active .sendTipButtonText {
background: var(--primary-dark-2) !important;
.sendTipButtonText {
color: var(--neutral-light-4) !important;
}
.sendTipName {
margin-left: 2.5px;
Expand Down
52 changes: 25 additions & 27 deletions packages/web/src/components/tipping/feed-tip-tile/FeedTipTile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect } from 'react'

import { Button, IconButton, useMediaQueryListener } from '@audius/stems'
import { IconButton, PillButton, useMediaQueryListener } from '@audius/stems'
import { push as pushRoute } from 'connected-react-router'
import { useDispatch, useSelector } from 'react-redux'

Expand Down Expand Up @@ -115,38 +115,36 @@ type SendTipToButtonProps = {
hideName?: boolean
}

const SendTipToButton = ({ user, hideName = false }: SendTipToButtonProps) => {
const SendTipButton = ({ user, hideName = false }: SendTipToButtonProps) => {
const dispatch = useDispatch()

const handleClick = useCallback(() => {
dispatch(beginTip({ user, source: 'feed' }))
}, [dispatch, user])

const renderSendTipButtonTitle = () =>
hideName ? (
messages.sendTip
) : (
<div className={styles.sendTipButtonTextContainer}>
{messages.sendTipToPrefix}
<span className={styles.sendTipName}>{user.name}</span>
<UserBadges
userId={user.user_id}
className={styles.badge}
badgeSize={12}
inline
/>
</div>
)

return (
<div>
<Button
className={styles.sendTipButton}
// todo: move to stems or see if button design
// already exists elsewhere
text={
hideName ? (
<div className={styles.sendTipButtonText}>{messages.sendTip}</div>
) : (
<div className={styles.sendTipButtonText}>
{messages.sendTipToPrefix}
<span className={styles.sendTipName}>{user.name}</span>
<UserBadges
userId={user.user_id}
className={styles.badge}
badgeSize={12}
inline
/>
</div>
)
}
onClick={handleClick}
/>
</div>
<PillButton
className={styles.sendTipButton}
textClassName={styles.sendTipButtonText}
text={renderSendTipButtonTitle()}
onClick={handleClick}
/>
)
}

Expand Down Expand Up @@ -257,7 +255,7 @@ export const FeedTipTile = () => {
/>
</div>
<div className={styles.buttons}>
<SendTipToButton
<SendTipButton
user={usersMap[tipToDisplay.receiver_id]}
hideName={useShortButtonFormat}
/>
Expand Down

0 comments on commit 2add00d

Please sign in to comment.