Repository navigation
Expand file tree
/
Copy pathButton.ts
More file actions
139 lines (127 loc) · 3.6 KB
/
Copy pathButton.ts
File metadata and controls
139 lines (127 loc) · 3.6 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
*
* Copyright © 2026 Extremely Heavy Industries Inc.
*/
import type {ButtonProps as BpButtonProps} from '@blueprintjs/core';
import type {
DomAttrsProps,
HoistModel,
HoistProps,
Intent,
LayoutProps,
StyleProps,
TestSupportProps
} from '@xh/hoist/core';
import {hoistCmp} from '@xh/hoist/core';
import '@xh/hoist/desktop/register';
import {button as bpButton} from '@xh/hoist/kit/blueprint';
import {TEST_ID, withDefault} from '@xh/hoist/utils/js';
import {splitLayoutProps} from '@xh/hoist/utils/react';
import classNames from 'classnames';
import type {ReactElement, ReactNode} from 'react';
import './Button.scss';
export interface ButtonProps<M extends HoistModel = null>
extends
HoistProps<M>,
StyleProps,
LayoutProps,
TestSupportProps,
DomAttrsProps,
Omit<BpButtonProps, 'ref'> {
active?: boolean;
autoFocus?: boolean;
disabled?: boolean;
icon?: ReactElement;
intent?: Intent;
minimal?: boolean;
outlined?: boolean;
rightIcon?: ReactElement;
text?: ReactNode;
title?: string;
value?: any;
tabIndex?: number; // TODO: where does this come from?
/** Alias for title. */
tooltip?: string;
}
export interface ButtonDefaults {
minimal?: boolean;
outlined?: boolean;
}
/**
* Wrapper around Blueprint's Button component. Defaults to the `minimal` style for reduced chrome
* and adds layout support for top-level sizing and margin/padding props.
*
* Relays all other props supported by Blueprint's button.
*/
export const [Button, button] = hoistCmp.withFactory<ButtonProps, ButtonDefaults>({
displayName: 'Button',
model: false,
className: 'xh-button',
defaults: {
minimal: true,
outlined: false
},
render(props, ref) {
const [layoutProps, nonLayoutProps] = splitLayoutProps(props),
classes = [],
{defaults} = Button;
const {
autoFocus,
className,
disabled,
icon,
intent,
minimal = defaults.minimal,
onClick,
outlined = defaults.outlined,
rightIcon,
style,
text,
title,
tooltip,
active,
testId,
domAttrs,
...rest
} = nonLayoutProps;
if (autoFocus) classes.push('xh-button--autofocus-enabled');
if (disabled) {
classes.push('xh-button--disabled');
} else {
classes.push('xh-button--enabled');
}
if (intent) {
classes.push(`xh-button--intent-${intent}`);
} else {
classes.push(`xh-button--intent-none`);
}
if (minimal) classes.push('xh-button--minimal');
if (outlined) classes.push('xh-button--outlined');
if (!minimal && !outlined) classes.push('xh-button--standard');
if (active) classes.push('xh-button--active');
return bpButton({
active,
autoFocus,
className: classNames(className, classes),
ref,
[TEST_ID]: testId,
...domAttrs,
disabled,
icon,
intent,
minimal,
onClick,
outlined,
rightIcon,
style: {
...style,
...layoutProps
},
text,
title: withDefault(title, tooltip),
...rest
});
}
});