| 1 |
import { Spinner } from '@wordpress/components'; |
| 2 |
import { chevronRight, Icon } from '@wordpress/icons'; |
| 3 |
|
| 4 |
const BASE = [ |
| 5 |
'inline-flex items-center rounded-ui-button font-normal transition-opacity', |
| 6 |
'[padding:var(--ext-ui-button-pad,8px)_var(--ext-ui-button-pad-x,12px)]', |
| 7 |
'[font-size:var(--ext-ui-button-size,14px)]', |
| 8 |
'[line-height:var(--ext-ui-button-leading,20px)]', |
| 9 |
'disabled:opacity-40', |
| 10 |
].join(' '); |
| 11 |
|
| 12 |
const LABEL = '[padding-inline:var(--ext-ui-button-label-pad,4px)]'; |
| 13 |
|
| 14 |
export const ACTION = [ |
| 15 |
BASE, |
| 16 |
'justify-center border-0 bg-ui-action text-ui-action-text hover:opacity-90', |
| 17 |
// A partner whose page and button colors match would otherwise see no button. |
| 18 |
'inset-ring-1 inset-ring-ui-action-text/25', |
| 19 |
'focus:outline-none focus-visible:ring-1 focus-visible:ring-ui-action focus-visible:ring-offset-2', |
| 20 |
].join(' '); |
| 21 |
|
| 22 |
export const SECONDARY = [ |
| 23 |
BASE, |
| 24 |
'bg-ui-secondary-fill ring-1 ring-ui-secondary-line', |
| 25 |
'text-ui-secondary-text hover:opacity-80', |
| 26 |
].join(' '); |
| 27 |
|
| 28 |
export const ActionButton = ({ |
| 29 |
label, |
| 30 |
icon = chevronRight, |
| 31 |
type = 'button', |
| 32 |
disabled, |
| 33 |
processing, |
| 34 |
onClick, |
| 35 |
}) => ( |
| 36 |
<button |
| 37 |
type={type} |
| 38 |
onClick={onClick} |
| 39 |
disabled={disabled || processing} |
| 40 |
className={ACTION} |
| 41 |
> |
| 42 |
<span className={LABEL}>{label}</span> |
| 43 |
{/* Fixed box: a spinner narrower than the arrow would shrink the button mid-click. */} |
| 44 |
<span className="flex h-6 w-6 items-center justify-center"> |
| 45 |
{processing ? ( |
| 46 |
<Spinner className="m-0" /> |
| 47 |
) : ( |
| 48 |
<Icon fill="currentColor" icon={icon} size={24} /> |
| 49 |
)} |
| 50 |
</span> |
| 51 |
</button> |
| 52 |
); |
| 53 |
|
| 54 |
export const SecondaryButton = ({ label, icon, disabled, onClick }) => ( |
| 55 |
<button |
| 56 |
type="button" |
| 57 |
onClick={onClick} |
| 58 |
disabled={disabled} |
| 59 |
className={SECONDARY} |
| 60 |
> |
| 61 |
{icon && <Icon fill="currentColor" icon={icon} size={24} />} |
| 62 |
<span className={LABEL}>{label}</span> |
| 63 |
</button> |
| 64 |
); |
| 65 |
|