-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathBpkButton.tsx
83 lines (75 loc) · 2.09 KB
/
BpkButton.tsx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Backpack - Skyscanner's Design System
*
* Copyright 2016 Skyscanner Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { cssModules } from '../../../bpk-react-utils';
import { BUTTON_TYPES, SIZE_TYPES } from './common-types';
import type { Props } from './common-types';
import COMMON_STYLES from './BpkButton.module.scss';
const getCommonClassName = cssModules(COMMON_STYLES);
// eslint-disable-next-line import/prefer-default-export
export const BpkButtonV2 = ({
blank = false,
children,
className = null,
disabled = false,
fullWidth = false,
href = null,
iconOnly = false,
onClick = () => {},
rel: propRel = undefined,
size = SIZE_TYPES.small,
submit = false,
type = BUTTON_TYPES.primary,
...rest
}: Props) => {
const classNames = getCommonClassName(
'bpk-button',
size === SIZE_TYPES.large && 'bpk-button--large',
iconOnly && 'bpk-button--icon-only',
iconOnly && size === SIZE_TYPES.large && 'bpk-button--large-icon-only',
`bpk-button--${type}`,
fullWidth && 'bpk-button--full-width',
className,
);
const target = blank ? '_blank' : '';
const rel = blank ? propRel || 'noopener noreferrer' : propRel;
if (!disabled && href) {
return (
<a
href={href}
className={classNames}
onClick={onClick}
target={target}
rel={rel}
{...rest}
>
{children}
</a>
);
}
return (
<button
type={submit ? 'submit' : 'button'}
disabled={disabled}
className={classNames}
onClick={onClick}
{...rest}
>
{children}
</button>
);
};