@bitrise/bitkit 13.210.1-alpha.0 → 13.211.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.0",
4
+ "version": "13.211.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' }}
@@ -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,14 +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;
5
+ queryKey?: string;
6
6
  tabIds: T[];
7
+ withHistory?: boolean;
7
8
  };
8
9
 
9
10
  const useTabs = <T extends string>(props: UseTabsProps<T>) => {
10
- const { defaultId, onChange, tabIds } = props;
11
+ const { defaultId, queryKey = 'tab', tabIds, withHistory } = props;
12
+
13
+ let searchParams = new URLSearchParams(window.location.search);
11
14
 
12
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
+ }
13
22
  if (defaultId) {
14
23
  const tabIndex = tabIds.indexOf(defaultId);
15
24
  if (tabIndex !== -1) {
@@ -26,9 +35,11 @@ const useTabs = <T extends string>(props: UseTabsProps<T>) => {
26
35
  }, []);
27
36
 
28
37
  useEffect(() => {
29
- if (onChange) {
30
- const id = tabIds[tabIndex];
31
- 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())}`);
32
43
  }
33
44
  }, [tabIndex]);
34
45