aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/ui/button.tsx
blob: 5274d835b663d76d9d6a63ae27a90ed2626620a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { darken, saturate } from 'polished';
import * as React from 'react';

import { ColorOption, styled } from '../../style/theme';

export interface ButtonProps {
    backgroundColor?: ColorOption;
    borderColor?: ColorOption;
    width?: string;
    padding?: string;
    type?: string;
    isDisabled?: boolean;
    onClick?: (event: React.MouseEvent<HTMLElement>) => void;
    className?: string;
}

const PlainButton: React.StatelessComponent<ButtonProps> = ({ children, isDisabled, onClick, type, className }) => (
    <button type={type} className={className} onClick={isDisabled ? undefined : onClick} disabled={isDisabled}>
        {children}
    </button>
);

const darkenOnHoverAmount = 0.1;
const darkenOnActiveAmount = 0.2;
const saturateOnFocusAmount = 0.2;
export const Button = styled(PlainButton)`
    cursor: ${props => (props.isDisabled ? 'default' : 'pointer')};
    transition: background-color, opacity 0.5s ease;
    padding: ${props => props.padding};
    border-radius: 3px;
    outline: none;
    width: ${props => props.width};
    background-color: ${props => (props.backgroundColor ? props.theme[props.backgroundColor] : 'none')};
    border: ${props => (props.borderColor ? `1px solid ${props.theme[props.borderColor]}` : 'none')};
    &:hover {
        background-color: ${props =>
            !props.isDisabled
                ? darken(darkenOnHoverAmount, props.theme[props.backgroundColor || 'white'])
                : ''} !important;
    }
    &:active {
        background-color: ${props =>
            !props.isDisabled ? darken(darkenOnActiveAmount, props.theme[props.backgroundColor || 'white']) : ''};
    }
    &:disabled {
        opacity: 0.5;
    }
    &:focus {
        background-color: ${props => saturate(saturateOnFocusAmount, props.theme[props.backgroundColor || 'white'])};
    }
`;

Button.defaultProps = {
    backgroundColor: ColorOption.primaryColor,
    borderColor: ColorOption.primaryColor,
    width: 'auto',
    isDisabled: false,
    padding: '1em 2.2em',
};

Button.displayName = 'Button';
9-11-09 16:13:40 +0800'>2019-11-091-3/+3 * Update Qt5 to 5.13.2tcberner2019-11-091-1/+0 * print, science: Add missing USES=gnometobik2019-11-0811-13/+14 * Register dependency on `graphics/giflib': while it is typically pickeddanfe2019-11-081-1/+2 * Sprinkle more USES=xorgzeising2019-11-081-0/+1 * Add USES=xorg USES=gl, ports categories pzeising2019-11-0723-22/+24 * Update `print/pslib' to version 0.4.6.danfe2019-11-073-9/+9 * Mark a few ports BROKEN (unfetchable)antoine2019-11-067-0/+14 * Returns johans's ports to the pool after safekeeping his commit bit.rene2019-11-052-2/+2 * Update to 1.19.8sunpoet2019-11-052-4/+4 * Update texi2dvisunpoet2019-11-042-4/+5 * print/hplip: Update to 3.19.10woodsb022019-11-0414-49/+403 * Cosmetic changesunpoet2019-11-041-2/+3 * Update version requirement of RUN_DEPENDSsunpoet2019-11-041-2/+2 * Cosmetic changesunpoet2019-11-041-2/+3 * print/hplip and print/hplip-plugin: Update to 3.18.6woodsb022019-11-035-10/+37 * print/gtklp: Update to 1.3.3tcberner2019-11-033-10/+11 * graphics/poppler: update to 0.82.0tcberner2019-11-0213-8/+62 * - Update to 0.17tota2019-11-012-4/+4 * print/pdf-tools: Include portclippy/portfmt formatting suggestionsjrm2019-11-011-4/+5 * print/pdf-tools: Update to 0.90.34jrm2019-11-012-5/+5 * print/harfbuzz: update to 2.6.4jbeich2019-10-312-5/+5 * print/harfbuzz: update to 2.6.3jbeich2019-10-293-6/+6 * Fix build with NLS disabledsunpoet2019-10-272-0/+24 * Update to 6.7sunpoet2019-10-263-11/+9 * print/xfce4-print: fix build on GCC architecturespkubaj2019-10-251-2/+2 * print/utopia : Update MAINTAINER, MASTER_SITESdmgk2019-10-201-6/+2 * Switch MASTER_SITES and WWW to https in Chris' ports.rakuco2019-10-192-2/+2 * Remove expired ports:rene2019-10-165-53/+0 * print/a2pdf : Update MAINTAINERdmgk2019-10-161-1/+1 * KDE Applications: update to 19.08.2tcberner2019-10-161-3/+3 * Update to 1.25.11.tijl2019-10-152-4/+4 * Update qpdfview to 0.4.18madpilot2019-10-102-5/+4 * Drop nop NO_FETCH, NO_WRKSRC, NO_MAN, NOMANtobik2019-10-094-4/+0 * Update to 1.25.7.tijl2019-10-083-32/+4 * Simplify the dependencies for print/py-fonttools, and enable optionsmat2019-10-0719-229/+32 * rename most cases of jakarta- to apache-pfg2019-10-071-2/+3 * devel/icu: update to 65.1jbeich2019-10-045-5/+5 * Update RUN_DEPENDS: use py-fonttools extra featuressunpoet2019-10-041-2/+3 * Change the way for optional dependenciessunpoet2019-10-021-27/+14 * Add py-fonttools-woff 3.44.0sunpoet2019-10-023-0/+26 * Add py-fonttools-unicode 3.44.0sunpoet2019-10-02