-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
439 additions
and
111 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
apps/audius-client/packages/stems/src/components/HarmonyButton/BaseButton.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* ===Base Styles=== */ | ||
.button { | ||
align-items: center; | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
display: inline-flex; | ||
flex-shrink: 0; | ||
justify-content: center; | ||
overflow: hidden; | ||
position: relative; | ||
text-align: center; | ||
user-select: none; | ||
white-space: nowrap; | ||
} | ||
|
||
.button:focus { | ||
outline: none !important; | ||
} | ||
|
||
/* Only add hover styles on devices which support it */ | ||
@media (hover: hover) { | ||
.button:not(.disabled):hover { | ||
transition: all var(--hover); | ||
transform: scale(1.04); | ||
} | ||
} | ||
|
||
.button:not(.disabled):active { | ||
transition: all var(--press); | ||
transform: scale(0.98); | ||
} | ||
|
||
.button.disabled { | ||
pointer-events: none; | ||
} | ||
|
||
.icon path { | ||
fill: currentColor; | ||
} | ||
|
||
.fullWidth { | ||
width: 100%; | ||
} |
76 changes: 76 additions & 0 deletions
76
apps/audius-client/packages/stems/src/components/HarmonyButton/BaseButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { forwardRef } from 'react' | ||
|
||
import cn from 'classnames' | ||
|
||
import { useMediaQueryListener } from 'hooks/useMediaQueryListener' | ||
|
||
import baseStyles from './BaseButton.module.css' | ||
import { BaseButtonProps } from './types' | ||
|
||
/** | ||
* Base component for Harmony buttons. Not intended to be used directly. Use | ||
* `HarmonyButton` or `HarmonyPlainButton`. | ||
*/ | ||
export const BaseButton = forwardRef<HTMLButtonElement, BaseButtonProps>( | ||
function BaseButton(props, ref) { | ||
const { | ||
text, | ||
iconLeft: LeftIconComponent, | ||
iconRight: RightIconComponent, | ||
disabled, | ||
widthToHideText, | ||
minWidth, | ||
className, | ||
'aria-label': ariaLabelProp, | ||
fullWidth, | ||
styles, | ||
style, | ||
...other | ||
} = props | ||
const { isMatch: textIsHidden } = useMediaQueryListener( | ||
`(max-width: ${widthToHideText}px)` | ||
) | ||
|
||
const isTextVisible = !!text && !textIsHidden | ||
|
||
const getAriaLabel = () => { | ||
if (ariaLabelProp) return ariaLabelProp | ||
// Use the text prop as the aria-label if the text becomes hidden | ||
// and no aria-label was provided to keep the button accessible. | ||
else if (textIsHidden && typeof text === 'string') return text | ||
return undefined | ||
} | ||
|
||
return ( | ||
<button | ||
aria-label={getAriaLabel()} | ||
className={cn( | ||
baseStyles.button, | ||
styles.button, | ||
{ | ||
[baseStyles.disabled]: disabled, | ||
[baseStyles.fullWidth]: fullWidth | ||
}, | ||
className | ||
)} | ||
disabled={disabled} | ||
ref={ref} | ||
style={{ | ||
minWidth: minWidth && isTextVisible ? `${minWidth}px` : 'unset', | ||
...style | ||
}} | ||
{...other} | ||
> | ||
{LeftIconComponent ? ( | ||
<LeftIconComponent className={cn(baseStyles.icon, styles.icon)} /> | ||
) : null} | ||
{isTextVisible ? ( | ||
<span className={cn(baseStyles.text, styles.text)}>{text}</span> | ||
) : null} | ||
{RightIconComponent ? ( | ||
<RightIconComponent className={cn(baseStyles.icon, styles.icon)} /> | ||
) : null} | ||
</button> | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/audius-client/packages/stems/src/components/HarmonyButton/HarmonyPlainButton.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* ===Base Styles=== */ | ||
.button { | ||
--text-color: var(--text-default); | ||
background: transparent; | ||
border: none; | ||
color: var(--text-color); | ||
} | ||
|
||
/* === Sizes === */ | ||
|
||
/* Default */ | ||
.buttonDefault { | ||
gap: var(--unit-1); | ||
height: var(--unit-4); | ||
} | ||
|
||
.iconDefault { | ||
width: var(--unit-4); | ||
height: var(--unit-4); | ||
} | ||
|
||
.textDefault { | ||
font-size: var(--font-s); | ||
font-weight: var(--font-bold); | ||
line-height: var(--unit-4); | ||
} | ||
|
||
/* Large */ | ||
.buttonLarge { | ||
gap: var(--unit-2); | ||
height: var(--unit-5); | ||
} | ||
|
||
.iconLarge { | ||
width: var(--unit-5); | ||
height: var(--unit-5); | ||
} | ||
|
||
.textLarge { | ||
font-size: var(--font-l); | ||
font-weight: var(--font-bold); | ||
line-height: calc(4.5 * var(--unit-5)); | ||
} | ||
|
||
/* === Color Variants === */ | ||
|
||
/* Default */ | ||
.default { | ||
--text-color: var(--text-default); | ||
} | ||
|
||
.default:hover { | ||
--text-color: var(--secondary); | ||
} | ||
|
||
.default:active { | ||
--text-color: var(--secondary-dark-2) | ||
} | ||
|
||
/* Subdued */ | ||
.subdued { | ||
--text-color: var(--text-subdued); | ||
} | ||
|
||
.subdued:hover { | ||
--text-color: var(--secondary); | ||
} | ||
.subdued:active { | ||
--text-color: var(--secondary-dark-2); | ||
} | ||
|
||
/* Inverted */ | ||
.inverted { | ||
--text-color: var(--static-white); | ||
} | ||
.inverted:hover { | ||
opacity: 0.8; | ||
} | ||
.inverted:active { | ||
opacity: 0.5; | ||
} | ||
|
||
/* Disabled states */ | ||
.disabled { | ||
opacity: 0.2; | ||
} | ||
|
||
.subdued.disabled { | ||
--text-color: var(--text-default); | ||
} |
Oops, something went wrong.