react-science 19.1.0 → 19.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/lib/components/form/components/hooks/use_input_id.d.ts +8 -0
  2. package/lib/components/form/components/hooks/use_input_id.d.ts.map +1 -0
  3. package/lib/components/form/components/hooks/use_input_id.js +15 -0
  4. package/lib/components/form/components/hooks/use_input_id.js.map +1 -0
  5. package/lib/components/form/components/input/checkbox.d.ts +5 -0
  6. package/lib/components/form/components/input/checkbox.d.ts.map +1 -0
  7. package/lib/components/form/components/input/checkbox.js +19 -0
  8. package/lib/components/form/components/input/checkbox.js.map +1 -0
  9. package/lib/components/form/components/input/input.d.ts +9 -0
  10. package/lib/components/form/components/input/input.d.ts.map +1 -0
  11. package/lib/components/form/components/input/input.js +16 -0
  12. package/lib/components/form/components/input/input.js.map +1 -0
  13. package/lib/components/form/components/input/numeric_input.d.ts +8 -0
  14. package/lib/components/form/components/input/numeric_input.d.ts.map +1 -0
  15. package/lib/components/form/components/input/numeric_input.js +20 -0
  16. package/lib/components/form/components/input/numeric_input.js.map +1 -0
  17. package/lib/components/form/components/input/reset_button.d.ts +7 -0
  18. package/lib/components/form/components/input/reset_button.d.ts.map +1 -0
  19. package/lib/components/form/components/input/reset_button.js +9 -0
  20. package/lib/components/form/components/input/reset_button.js.map +1 -0
  21. package/lib/components/form/components/input/select.d.ts +12 -0
  22. package/lib/components/form/components/input/select.d.ts.map +1 -0
  23. package/lib/components/form/components/input/select.js +25 -0
  24. package/lib/components/form/components/input/select.js.map +1 -0
  25. package/lib/components/form/components/input/submit_button.d.ts +5 -0
  26. package/lib/components/form/components/input/submit_button.d.ts.map +1 -0
  27. package/lib/components/form/components/input/submit_button.js +11 -0
  28. package/lib/components/form/components/input/submit_button.js.map +1 -0
  29. package/lib/components/form/components/input/switch.d.ts +6 -0
  30. package/lib/components/form/components/input/switch.d.ts.map +1 -0
  31. package/lib/components/form/components/input/switch.js +16 -0
  32. package/lib/components/form/components/input/switch.js.map +1 -0
  33. package/lib/components/form/components/input_groups/input.d.ts +20 -0
  34. package/lib/components/form/components/input_groups/input.d.ts.map +1 -0
  35. package/lib/components/form/components/input_groups/input.js +9 -0
  36. package/lib/components/form/components/input_groups/input.js.map +1 -0
  37. package/lib/components/form/components/input_groups/select.d.ts +59 -0
  38. package/lib/components/form/components/input_groups/select.d.ts.map +1 -0
  39. package/lib/components/form/components/input_groups/select.js +29 -0
  40. package/lib/components/form/components/input_groups/select.js.map +1 -0
  41. package/lib/components/form/components/util/select.d.ts +20 -0
  42. package/lib/components/form/components/util/select.d.ts.map +1 -0
  43. package/lib/components/form/components/util/select.js +20 -0
  44. package/lib/components/form/components/util/select.js.map +1 -0
  45. package/lib/components/form/context/use_ts_form.d.ts +41 -0
  46. package/lib/components/form/context/use_ts_form.d.ts.map +1 -0
  47. package/lib/components/form/context/use_ts_form.js +27 -0
  48. package/lib/components/form/context/use_ts_form.js.map +1 -0
  49. package/lib/components/form/utils/use_field_id.d.ts +2 -0
  50. package/lib/components/form/utils/use_field_id.d.ts.map +1 -0
  51. package/lib/components/form/utils/use_field_id.js +5 -0
  52. package/lib/components/form/utils/use_field_id.js.map +1 -0
  53. package/lib/components/form/utils/use_intent.d.ts +3 -0
  54. package/lib/components/form/utils/use_intent.d.ts.map +1 -0
  55. package/lib/components/form/utils/use_intent.js +4 -0
  56. package/lib/components/form/utils/use_intent.js.map +1 -0
  57. package/lib/components/index.d.ts +2 -1
  58. package/lib/components/index.d.ts.map +1 -1
  59. package/lib/components/index.js +2 -1
  60. package/lib/components/index.js.map +1 -1
  61. package/lib/components/input/index.d.ts.map +1 -0
  62. package/lib/components/input/index.js.map +1 -0
  63. package/lib/components/{forms → input}/radio-button-group/RadioButton.d.ts.map +1 -1
  64. package/lib/components/{forms → input}/radio-button-group/RadioButton.js.map +1 -1
  65. package/lib/components/{forms → input}/radio-button-group/RadioButtonGroup.d.ts.map +1 -1
  66. package/lib/components/{forms → input}/radio-button-group/RadioButtonGroup.js.map +1 -1
  67. package/lib/components/{forms → input}/radio-button-group/index.d.ts.map +1 -1
  68. package/lib/components/input/radio-button-group/index.js.map +1 -0
  69. package/lib/components/input/styles.d.ts.map +1 -0
  70. package/lib/components/{forms → input}/styles.js.map +1 -1
  71. package/lib/components/{forms → input}/utils/SubText.d.ts.map +1 -1
  72. package/lib/components/{forms → input}/utils/SubText.js.map +1 -1
  73. package/lib/components/input/utils/index.d.ts.map +1 -0
  74. package/lib/components/input/utils/index.js.map +1 -0
  75. package/lib/components/{forms → input}/utils/use_input_id.d.ts.map +1 -1
  76. package/lib/components/{forms → input}/utils/use_input_id.js.map +1 -1
  77. package/lib/components/toolbar/Toolbar.d.ts.map +1 -1
  78. package/lib/components/toolbar/Toolbar.js +2 -1
  79. package/lib/components/toolbar/Toolbar.js.map +1 -1
  80. package/package.json +4 -2
  81. package/src/components/form/components/hooks/use_input_id.ts +19 -0
  82. package/src/components/form/components/input/checkbox.tsx +36 -0
  83. package/src/components/form/components/input/input.tsx +37 -0
  84. package/src/components/form/components/input/numeric_input.tsx +49 -0
  85. package/src/components/form/components/input/reset_button.tsx +19 -0
  86. package/src/components/form/components/input/select.tsx +47 -0
  87. package/src/components/form/components/input/submit_button.tsx +23 -0
  88. package/src/components/form/components/input/switch.tsx +33 -0
  89. package/src/components/form/components/input_groups/input.tsx +63 -0
  90. package/src/components/form/components/input_groups/select.tsx +196 -0
  91. package/src/components/form/components/util/select.tsx +67 -0
  92. package/src/components/form/context/use_ts_form.ts +31 -0
  93. package/src/components/form/utils/use_field_id.ts +5 -0
  94. package/src/components/form/utils/use_intent.ts +5 -0
  95. package/src/components/index.ts +2 -1
  96. package/src/components/toolbar/Toolbar.tsx +2 -1
  97. package/lib/components/forms/index.d.ts.map +0 -1
  98. package/lib/components/forms/index.js.map +0 -1
  99. package/lib/components/forms/radio-button-group/index.js.map +0 -1
  100. package/lib/components/forms/styles.d.ts.map +0 -1
  101. package/lib/components/forms/utils/index.d.ts.map +0 -1
  102. package/lib/components/forms/utils/index.js.map +0 -1
  103. /package/lib/components/{forms → input}/index.d.ts +0 -0
  104. /package/lib/components/{forms → input}/index.js +0 -0
  105. /package/lib/components/{forms → input}/radio-button-group/RadioButton.d.ts +0 -0
  106. /package/lib/components/{forms → input}/radio-button-group/RadioButton.js +0 -0
  107. /package/lib/components/{forms → input}/radio-button-group/RadioButtonGroup.d.ts +0 -0
  108. /package/lib/components/{forms → input}/radio-button-group/RadioButtonGroup.js +0 -0
  109. /package/lib/components/{forms → input}/radio-button-group/index.d.ts +0 -0
  110. /package/lib/components/{forms → input}/radio-button-group/index.js +0 -0
  111. /package/lib/components/{forms → input}/styles.d.ts +0 -0
  112. /package/lib/components/{forms → input}/styles.js +0 -0
  113. /package/lib/components/{forms → input}/utils/SubText.d.ts +0 -0
  114. /package/lib/components/{forms → input}/utils/SubText.js +0 -0
  115. /package/lib/components/{forms → input}/utils/index.d.ts +0 -0
  116. /package/lib/components/{forms → input}/utils/index.js +0 -0
  117. /package/lib/components/{forms → input}/utils/use_input_id.d.ts +0 -0
  118. /package/lib/components/{forms → input}/utils/use_input_id.js +0 -0
  119. /package/src/components/{forms → input}/index.ts +0 -0
  120. /package/src/components/{forms → input}/radio-button-group/RadioButton.tsx +0 -0
  121. /package/src/components/{forms → input}/radio-button-group/RadioButtonGroup.tsx +0 -0
  122. /package/src/components/{forms → input}/radio-button-group/index.ts +0 -0
  123. /package/src/components/{forms → input}/styles.ts +0 -0
  124. /package/src/components/{forms → input}/utils/SubText.tsx +0 -0
  125. /package/src/components/{forms → input}/utils/index.ts +0 -0
  126. /package/src/components/{forms → input}/utils/use_input_id.ts +0 -0
@@ -0,0 +1,196 @@
1
+ import type { FormGroupProps } from '@blueprintjs/core';
2
+ import { FormGroup } from '@blueprintjs/core';
3
+ import type { SelectProps as BPSelectProps } from '@blueprintjs/select';
4
+ import { Select as BPSelect } from '@blueprintjs/select';
5
+ import type { ComponentProps, ReactElement, ReactNode } from 'react';
6
+ import { useCallback, useMemo } from 'react';
7
+
8
+ import { Button } from '../../../button/index.js';
9
+ import { useInputId } from '../hooks/use_input_id.js';
10
+ import type {
11
+ GetOptionLabel,
12
+ GetOptionValue,
13
+ SelectId,
14
+ SelectOption,
15
+ SelectOptionLabel,
16
+ } from '../util/select.js';
17
+ import {
18
+ getItemRenderer,
19
+ getSelectLabel,
20
+ getSelectValue,
21
+ } from '../util/select.js';
22
+
23
+ type FieldGroupProps = Pick<FormGroupProps, 'label' | 'inline'>;
24
+
25
+ export interface SelectPropsRenderButtonState<OptionType> {
26
+ error: string | undefined;
27
+ selectedOption: OptionType | undefined;
28
+ }
29
+
30
+ interface SelectCustomProps<OptionType, ID extends SelectId> {
31
+ renderButton?: (state: SelectPropsRenderButtonState<OptionType>) => ReactNode;
32
+ onChange?: (selected: ID | undefined, option: OptionType | undefined) => void;
33
+ id?: string;
34
+ selected?: ID;
35
+
36
+ required?: boolean;
37
+ }
38
+
39
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
40
+ type SelectGetValue<OptionType, ID extends SelectId> = {
41
+ /**
42
+ * Optional if OptionType extends SelectOption<ID>
43
+ * @default getSelectValue
44
+ */
45
+ getValue: GetOptionValue<OptionType, ID>;
46
+ };
47
+
48
+ type SelectGetValueProps<OptionType, ID extends SelectId> =
49
+ OptionType extends SelectOption<ID>
50
+ ? Partial<SelectGetValue<OptionType, ID>>
51
+ : SelectGetValue<OptionType, ID>;
52
+
53
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
54
+ type SelectGetLabel<OptionType> = {
55
+ /**
56
+ * Optional if OptionType extends SelectOptionLabel
57
+ * @default getSelectLabel
58
+ */
59
+ getLabel: GetOptionLabel<OptionType>;
60
+ };
61
+
62
+ type SelectGetLabelProps<OptionType> = OptionType extends SelectOptionLabel
63
+ ? Partial<SelectGetLabel<OptionType>>
64
+ : SelectGetLabel<OptionType>;
65
+
66
+ export type SelectProps<OptionType, ID extends SelectId> = FieldGroupProps &
67
+ Pick<
68
+ BPSelectProps<OptionType>,
69
+ | 'placeholder'
70
+ | 'items'
71
+ | 'className'
72
+ | 'disabled'
73
+ | 'popoverProps'
74
+ | 'filterable'
75
+ | 'itemDisabled'
76
+ | 'itemListPredicate'
77
+ | 'resetOnClose'
78
+ > &
79
+ Pick<ComponentProps<typeof FormGroup>, 'helperText' | 'intent'> &
80
+ SelectCustomProps<OptionType, ID> &
81
+ SelectGetValueProps<OptionType, ID> &
82
+ SelectGetLabelProps<OptionType>;
83
+
84
+ /**
85
+ * A wrapper for the BlueprintJS Select component that integrates with react-hook-form.
86
+ * Store in form the selected value.
87
+ * Find selected option getValue.
88
+ * Display options with getLabel.
89
+ *
90
+ * @param props
91
+ * @constructor
92
+ */
93
+
94
+ interface RealSelectProps<OptionType, ID extends SelectId>
95
+ extends Pick<BPSelectProps<OptionType>, 'filterable' | 'items'> {
96
+ onBlur: () => void;
97
+ id?: string;
98
+ renderButton?: (
99
+ state: SelectPropsRenderButtonState<OptionType>,
100
+ onBlur: () => void,
101
+ ) => ReactNode;
102
+ disabled?: boolean;
103
+ selected?: ID;
104
+ onChange?: (selected: ID | undefined, option: OptionType | undefined) => void;
105
+ getLabel?: GetOptionLabel<OptionType>;
106
+ getValue?: GetOptionValue<OptionType, ID>;
107
+ formGroupProps: Pick<
108
+ ComponentProps<typeof FormGroup>,
109
+ 'helperText' | 'intent' | 'label' | 'className' | 'inline'
110
+ > & {
111
+ required?: boolean;
112
+ };
113
+ }
114
+
115
+ export function Select<
116
+ OptionType extends SelectOption<ID>,
117
+ ID extends SelectId,
118
+ >(props: RealSelectProps<OptionType, ID>): ReactElement {
119
+ const {
120
+ renderButton,
121
+ id,
122
+ disabled,
123
+ selected,
124
+ getLabel: _getLabel,
125
+ getValue: _getValue,
126
+ formGroupProps: { className, helperText, inline, intent, label, required },
127
+ // Weirdly, setting the filterable prop on BP's Select component activates the filter input
128
+ filterable = false,
129
+ items,
130
+ onChange,
131
+ onBlur,
132
+ } = props;
133
+
134
+ const getValue: GetOptionValue<OptionType, ID> = _getValue ?? getSelectValue;
135
+ const getLabel: GetOptionLabel<OptionType> = _getLabel ?? getSelectLabel;
136
+
137
+ const selectedOption = useMemo(
138
+ () => items.find((item) => getValue(item) === selected),
139
+ [getValue, items, selected],
140
+ );
141
+
142
+ const itemRenderer = useMemo(() => {
143
+ return getItemRenderer<OptionType, ID>({
144
+ selected,
145
+ getValue,
146
+ getLabel,
147
+ });
148
+ }, [getLabel, getValue, selected]);
149
+
150
+ const onItemSelect = useCallback(
151
+ (option: OptionType | undefined) => {
152
+ const value = getValue(option);
153
+ onChange?.(value, option);
154
+ },
155
+ [getValue, onChange],
156
+ );
157
+
158
+ const inputId = useInputId(id, null);
159
+
160
+ return (
161
+ <FormGroup
162
+ label={label}
163
+ labelFor={inputId}
164
+ helperText={helperText}
165
+ intent={intent}
166
+ style={{ margin: 0, position: 'relative' }}
167
+ className={className}
168
+ inline={inline}
169
+ disabled={disabled}
170
+ labelInfo={required && <span style={{ color: 'red' }}>*</span>}
171
+ >
172
+ <BPSelect<OptionType>
173
+ filterable={filterable}
174
+ items={items}
175
+ onItemSelect={onItemSelect}
176
+ itemRenderer={itemRenderer}
177
+ disabled={disabled}
178
+ >
179
+ {renderButton ? (
180
+ renderButton({ selectedOption, error: undefined }, onBlur)
181
+ ) : (
182
+ <Button
183
+ id={inputId}
184
+ text={getLabel(selectedOption) || 'Select ...'}
185
+ endIcon="double-caret-vertical"
186
+ variant="outlined"
187
+ intent={intent}
188
+ disabled={disabled}
189
+ style={{ minWidth: 180 }}
190
+ onBlur={onBlur}
191
+ />
192
+ )}
193
+ </BPSelect>
194
+ </FormGroup>
195
+ );
196
+ }
@@ -0,0 +1,67 @@
1
+ import { MenuItem } from '@blueprintjs/core';
2
+ import type { ItemRenderer } from '@blueprintjs/select';
3
+ import type { ReactNode } from 'react';
4
+
5
+ export type SelectId = string | number | null;
6
+
7
+ export type GetOptionValue<OptionType, ID extends SelectId> = (
8
+ option: OptionType | undefined,
9
+ ) => ID | undefined;
10
+ export type GetOptionLabel<OptionType> = (
11
+ option: OptionType | undefined,
12
+ ) => ReactNode;
13
+
14
+ export interface GetItemRendererOptions<OptionType, ID extends SelectId> {
15
+ selected: ID | undefined;
16
+ getValue: GetOptionValue<OptionType, ID>;
17
+ getLabel: GetOptionLabel<OptionType>;
18
+ }
19
+
20
+ export function getItemRenderer<OptionType, ID extends SelectId>(
21
+ options: GetItemRendererOptions<OptionType, ID>,
22
+ ) {
23
+ const { selected, getValue, getLabel } = options;
24
+
25
+ const render: ItemRenderer<OptionType> = (
26
+ item,
27
+ { handleClick, handleFocus, modifiers, index },
28
+ ) => {
29
+ const label = getLabel(item);
30
+ const { active, disabled, matchesPredicate } = modifiers;
31
+ if (!matchesPredicate) return null;
32
+ return (
33
+ <MenuItem
34
+ active={active}
35
+ disabled={disabled}
36
+ selected={selected === getValue(item)}
37
+ key={index}
38
+ onClick={handleClick}
39
+ onFocus={handleFocus}
40
+ roleStructure="listoption"
41
+ text={label}
42
+ />
43
+ );
44
+ };
45
+
46
+ return render;
47
+ }
48
+
49
+ export interface SelectOptionLabel {
50
+ label: string;
51
+ }
52
+
53
+ export function getSelectLabel(
54
+ option: SelectOptionLabel | undefined,
55
+ ): string | undefined {
56
+ return option?.label;
57
+ }
58
+
59
+ export interface SelectOption<ID> extends SelectOptionLabel {
60
+ value: ID;
61
+ }
62
+
63
+ export function getSelectValue<Option extends SelectOption<unknown>>(
64
+ option: Option | undefined,
65
+ ): Option['value'] | undefined {
66
+ return option?.value;
67
+ }
@@ -0,0 +1,31 @@
1
+ import { createFormHook, createFormHookContexts } from '@tanstack/react-form';
2
+
3
+ import { Checkbox } from '../components/input/checkbox.js';
4
+ import { Input } from '../components/input/input.js';
5
+ import { NumericInput } from '../components/input/numeric_input.js';
6
+ import { ResetButton } from '../components/input/reset_button.js';
7
+ import { Select } from '../components/input/select.js';
8
+ import { SubmitButton } from '../components/input/submit_button.js';
9
+ import { Switch } from '../components/input/switch.js';
10
+
11
+ const { useFormContext, useFieldContext, formContext, fieldContext } =
12
+ createFormHookContexts();
13
+
14
+ const { useAppForm, withForm } = createFormHook({
15
+ fieldContext,
16
+ formContext,
17
+ formComponents: {
18
+ SubmitButton,
19
+ ResetButton,
20
+ },
21
+ fieldComponents: {
22
+ Input,
23
+ NumericInput,
24
+ Checkbox,
25
+ Select,
26
+ Switch,
27
+ },
28
+ });
29
+
30
+ export const useForm = useAppForm;
31
+ export { useFieldContext, useFormContext, withForm };
@@ -0,0 +1,5 @@
1
+ import { useId } from 'react';
2
+
3
+ export function useFieldId(fieldName: string) {
4
+ return `input-${fieldName}-${useId()}`;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { Intent } from '@blueprintjs/core';
2
+
3
+ export function getIntent(error?: string): Intent | undefined {
4
+ return error !== undefined ? 'danger' : undefined;
5
+ }
@@ -4,7 +4,7 @@ export * from './color-picker/index.js';
4
4
  export * from './dialog/index.js';
5
5
  export * from './doi/index.js';
6
6
  export * from './drop-zone/index.js';
7
- export * from './forms/index.js';
7
+ export * from './input/index.js';
8
8
  export * from './fullscreen/index.js';
9
9
  export * from './header/index.js';
10
10
  export * from './hooks/index.js';
@@ -14,6 +14,7 @@ export * from './root-layout/index.js';
14
14
  export * from './split_pane/index.js';
15
15
  export * from './table/index.js';
16
16
  export * from './toolbar/index.js';
17
+ export * from './form/context/use_ts_form.js';
17
18
  export * from './activity_bar/index.js';
18
19
  export * from './activity_panel/index.js';
19
20
  export * from './utils/index.js';
@@ -60,7 +60,8 @@ const border = '1px solid rgb(247, 247, 247)';
60
60
 
61
61
  const ToolbarButton = styled(Button)`
62
62
  .${Classes.ICON} {
63
- color: ${Colors.DARK_GRAY3};
63
+ /* Color of icon in button is lighter in Blueprintjs. We want a better contrast in the toolbars */
64
+ color: ${Colors.DARK_GRAY3} !important;
64
65
  width: 16px;
65
66
  height: 16px;
66
67
  font-size: 12px;
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/forms/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/forms/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/forms/radio-button-group/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/components/forms/styles.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,YAAY,CAAC;AACtC,eAAO,MAAM,aAAa,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/forms/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes