@bitrise/bitkit 13.210.1-alpha.1 → 13.212.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "13.210.1-alpha.1",
4
+ "version": "13.212.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -24,6 +24,8 @@ const FormLabel = forwardRef<FormLabelProps, 'label'>((props, ref) => {
24
24
  return null;
25
25
  }
26
26
 
27
+ const counterColor = maxLength && valueLength && valueLength > maxLength ? 'input/text/error' : 'text/secondary';
28
+
27
29
  return (
28
30
  <Box alignItems="center" display="flex" gap="4" marginBlockEnd="4">
29
31
  <ChakraFormLabel
@@ -48,7 +50,7 @@ const FormLabel = forwardRef<FormLabelProps, 'label'>((props, ref) => {
48
50
  {!badge && withCounter && maxLength && (
49
51
  <Text
50
52
  as="span"
51
- color="text/secondary"
53
+ color={counterColor}
52
54
  marginInlineStart="auto"
53
55
  size="2"
54
56
  sx={{ fontVariantNumeric: 'tabular-nums' }}
@@ -41,6 +41,7 @@ type UsedChakraInputProps = Pick<
41
41
  | 'placeholder'
42
42
  | 'step'
43
43
  >;
44
+
44
45
  export interface InputProps extends UsedFormControlProps, UsedChakraInputProps {
45
46
  badge?: FormLabelProps['badge'];
46
47
  errorText?: ReactNode;
@@ -57,12 +58,12 @@ export interface InputProps extends UsedFormControlProps, UsedChakraInputProps {
57
58
  leftAddonPlacement?: 'inside' | 'outside';
58
59
  leftIconColor?: IconProps['color'];
59
60
  leftIconName?: TypeIconName;
61
+ recommendedLength?: number;
60
62
  rightAddon?: ReactNode;
61
63
  rightAddonPlacement?: 'inside' | 'outside';
62
64
  rightIconName?: TypeIconName;
63
65
  rightIconColor?: IconProps['color'];
64
66
  size?: 'lg' | 'md';
65
- withCounter?: boolean;
66
67
  warningText?: ReactNode;
67
68
  }
68
69
 
@@ -75,7 +76,7 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
75
76
  autoFocus,
76
77
  badge,
77
78
  defaultValue,
78
- errorText,
79
+ errorText: errorTextProp,
79
80
  helperText,
80
81
  infoTooltipLabel,
81
82
  infoTooltipProps,
@@ -100,6 +101,7 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
100
101
  onChange,
101
102
  pattern,
102
103
  placeholder,
104
+ recommendedLength,
103
105
  rightAddon,
104
106
  rightAddonPlacement,
105
107
  rightIconName,
@@ -110,10 +112,15 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
110
112
  type,
111
113
  value,
112
114
  warningText,
113
- withCounter,
114
115
  ...rest
115
116
  } = props;
116
117
 
118
+ const [valueLength, setValueLength] = useState(value?.toString().length || 0);
119
+
120
+ const exceedsCharacterLimitError =
121
+ recommendedLength && valueLength > recommendedLength ? 'Text exceeds the character limit.' : undefined;
122
+ const errorText = errorTextProp || exceedsCharacterLimitError;
123
+
117
124
  const formControlProps = {
118
125
  isDisabled: isDisabled || isLoading,
119
126
  isInvalid: isInvalid || !!errorText,
@@ -151,8 +158,6 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
151
158
  const LeftContentWrapper = leftAddonPlacement === 'inside' ? InputLeftElement : InputLeftAddon;
152
159
  const inputLeftPadding = leftIconName || (leftAddon && leftAddonPlacement === 'inside') ? '43px' : inputInlinePadding;
153
160
 
154
- const [valueLength, setValueLength] = useState(value?.toString().length || 0);
155
-
156
161
  const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
157
162
  setValueLength(e.currentTarget.value.length);
158
163
 
@@ -170,9 +175,9 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
170
175
  badge={badge}
171
176
  infoTooltipLabel={infoTooltipLabel}
172
177
  infoTooltipProps={infoTooltipProps}
173
- maxLength={maxLength}
178
+ maxLength={maxLength || recommendedLength}
174
179
  valueLength={valueLength}
175
- withCounter={withCounter}
180
+ withCounter={Boolean(maxLength || recommendedLength)}
176
181
  >
177
182
  {label}
178
183
  </FormLabel>
@@ -27,7 +27,7 @@ type UsedChakraTextProps = Pick<
27
27
  | 'placeholder'
28
28
  >;
29
29
 
30
- export interface TextareaProps extends UsedFormControlProps, UsedChakraTextProps {
30
+ export type TextareaProps = {
31
31
  badge?: FormLabelProps['badge'];
32
32
  errorText?: string;
33
33
  infoTooltipLabel?: string;
@@ -35,12 +35,24 @@ export interface TextareaProps extends UsedFormControlProps, UsedChakraTextProps
35
35
  isLoading?: boolean;
36
36
  helperText?: string;
37
37
  label?: FormLabelProps['children'];
38
+ maxLength?: number;
39
+ recommendedLength?: number;
38
40
  name?: string;
39
41
  onBlur?: ChakraTextareaProps['onBlur'];
40
42
  onChange?: ChakraTextareaProps['onChange'];
41
43
  value?: ChakraTextareaProps['value'];
42
- withCounter?: boolean;
43
- }
44
+ } & UsedFormControlProps &
45
+ UsedChakraTextProps &
46
+ (
47
+ | {
48
+ recommendedLength?: number;
49
+ maxLength?: never;
50
+ }
51
+ | {
52
+ recommendedLength?: never;
53
+ maxLength?: number;
54
+ }
55
+ );
44
56
 
45
57
  /**
46
58
  * The Textarea component allows you to easily create multi-line text inputs.
@@ -50,7 +62,7 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
50
62
  autoComplete,
51
63
  autoFocus,
52
64
  badge,
53
- errorText,
65
+ errorText: errorTextProp,
54
66
  helperText,
55
67
  infoTooltipLabel,
56
68
  infoTooltipProps,
@@ -64,12 +76,20 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
64
76
  onBlur,
65
77
  onChange,
66
78
  placeholder,
79
+ recommendedLength,
67
80
  resize,
68
81
  role,
69
82
  value,
70
- withCounter,
71
83
  ...rest
72
84
  } = props;
85
+
86
+ const [valueLength, setValueLength] = useState(value?.toString().length || 0);
87
+
88
+ const exceedsCharacterLimitError =
89
+ recommendedLength && valueLength > recommendedLength ? 'Text exceeds the character limit.' : undefined;
90
+
91
+ const errorText = errorTextProp || exceedsCharacterLimitError;
92
+
73
93
  const formControlProps = {
74
94
  isDisabled: isDisabled || isLoading,
75
95
  isInvalid: isInvalid || !!errorText,
@@ -89,8 +109,6 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
89
109
  value,
90
110
  };
91
111
 
92
- const [valueLength, setValueLength] = useState(value?.toString().length || 0);
93
-
94
112
  const onTextareaChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
95
113
  setValueLength(e.currentTarget.value.length);
96
114
 
@@ -107,16 +125,16 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
107
125
  badge={badge}
108
126
  infoTooltipLabel={infoTooltipLabel}
109
127
  infoTooltipProps={infoTooltipProps}
110
- maxLength={maxLength}
128
+ maxLength={maxLength || recommendedLength}
111
129
  valueLength={valueLength}
112
- withCounter={withCounter}
130
+ withCounter={Boolean(maxLength || recommendedLength)}
113
131
  >
114
132
  {label}
115
133
  </FormLabel>
116
134
 
117
135
  <ChakraTextarea {...textareaProps} {...dataAttributes} onChange={onTextareaChange} />
118
136
  {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
119
- {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
137
+ {!errorText && helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
120
138
  </FormControl>
121
139
  );
122
140
  });
@@ -2,16 +2,23 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
2
2
 
3
3
  type UseTabsProps<T> = {
4
4
  defaultId?: T;
5
- onChange?: (id: T, index: number) => void;
6
- tabIds: T[];
7
5
  queryKey?: string;
6
+ tabIds: T[];
8
7
  withHistory?: boolean;
9
8
  };
10
9
 
11
10
  const useTabs = <T extends string>(props: UseTabsProps<T>) => {
12
- const { defaultId, onChange, tabIds } = props;
11
+ const { defaultId, queryKey = 'tab', tabIds, withHistory } = props;
12
+
13
+ let searchParams = new URLSearchParams(window.location.search);
13
14
 
14
15
  const defaultIndex = useMemo(() => {
16
+ if (withHistory && searchParams.get(queryKey)) {
17
+ const tabIndex = tabIds.indexOf(searchParams.get(queryKey) as T);
18
+ if (tabIndex !== -1) {
19
+ return tabIndex;
20
+ }
21
+ }
15
22
  if (defaultId) {
16
23
  const tabIndex = tabIds.indexOf(defaultId);
17
24
  if (tabIndex !== -1) {
@@ -28,9 +35,11 @@ const useTabs = <T extends string>(props: UseTabsProps<T>) => {
28
35
  }, []);
29
36
 
30
37
  useEffect(() => {
31
- if (onChange) {
32
- const id = tabIds[tabIndex];
33
- onChange(id, tabIndex);
38
+ const queryValue = tabIds[tabIndex];
39
+ if (withHistory && queryValue) {
40
+ searchParams = new URLSearchParams(window.location.search);
41
+ searchParams.set(queryKey, queryValue);
42
+ window.parent.history.replaceState(null, '', `?${decodeURIComponent(searchParams.toString())}`);
34
43
  }
35
44
  }, [tabIndex]);
36
45