@bitrise/bitkit 10.29.0 → 10.30.0-alpha-input.1

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": "10.29.0",
4
+ "version": "10.30.0-alpha-input.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -22,6 +22,7 @@
22
22
  "dependencies": {
23
23
  "@chakra-ui/react": "^2.2.4",
24
24
  "@chakra-ui/react-utils": "^2.0.1",
25
+ "@chakra-ui/styled-system": "^2.3.1",
25
26
  "@chakra-ui/utils": "^2.0.4",
26
27
  "@emotion/react": "^11.9.3",
27
28
  "@emotion/styled": "^11.9.3",
@@ -1,15 +1,8 @@
1
1
  import React, { cloneElement, forwardRef, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import {
3
- chakra,
4
- ChakraProps,
5
- Input,
6
- InputGroup,
7
- InputLeftElement,
8
- useControllableState,
9
- useMultiStyleConfig,
10
- } from '@chakra-ui/react';
2
+ import { chakra, ChakraProps, useControllableState, useMultiStyleConfig } from '@chakra-ui/react';
11
3
  import { FloatingFocusManager, UseFloatingProps } from '@floating-ui/react-dom-interactions';
12
- import Icon, { TypeIconName } from '../Icon/Icon';
4
+ import { TypeIconName } from '../Icon/Icon';
5
+ import Input from '../Form/Input/Input';
13
6
  import { DropdownEventArgs, DropdownProvider, useDropdownContext, useDropdownStyles } from './Dropdown.context';
14
7
  import { DropdownOption, DropdownGroup, DropdownDetailedOption, DropdownOptionProps } from './DropdownOption';
15
8
  import DropdownButton from './DropdownButton';
@@ -55,21 +48,17 @@ const DropdownSearch = ({
55
48
  [searchOnSubmit],
56
49
  );
57
50
  return (
58
- <InputGroup sx={search}>
59
- <InputLeftElement pointerEvents="none">
60
- <Icon aria-hidden color="neutral.60" size="24" name="Magnifier" />
61
- </InputLeftElement>
62
- <Input
63
- onKeyDown={onKeyDown}
64
- ref={searchRef}
65
- role="search"
66
- aria-label={placeholder}
67
- width="100%"
68
- placeholder={placeholder}
69
- value={value}
70
- onChange={onChangeCB}
71
- />
72
- </InputGroup>
51
+ <Input
52
+ onKeyDown={onKeyDown}
53
+ inputRef={searchRef}
54
+ role="search"
55
+ aria-label={placeholder}
56
+ placeholder={placeholder}
57
+ value={value}
58
+ onChange={onChangeCB}
59
+ leftIconName="Magnifier"
60
+ sx={search}
61
+ />
73
62
  );
74
63
  };
75
64
  export { DropdownOption, DropdownGroup, DropdownSearch, NoResultsFound, DropdownDetailedOption };
@@ -0,0 +1,9 @@
1
+ import { FormHelperText as ChakraFormHelperText, HelpTextProps, forwardRef } from '@chakra-ui/react';
2
+
3
+ const FormHelperText = forwardRef<HelpTextProps, 'div'>((props, ref) => {
4
+ return <ChakraFormHelperText {...props} ref={ref} />;
5
+ });
6
+
7
+ export type { HelpTextProps };
8
+
9
+ export default FormHelperText;
@@ -0,0 +1,9 @@
1
+ import { FormLabel as ChakraFormLabel, FormLabelProps, forwardRef } from '@chakra-ui/react';
2
+
3
+ const FormLabel = forwardRef<FormLabelProps, 'label'>((props, ref) => {
4
+ return <ChakraFormLabel {...props} ref={ref} />;
5
+ });
6
+
7
+ export type { FormLabelProps };
8
+
9
+ export default FormLabel;
@@ -0,0 +1,52 @@
1
+ import { ComponentMeta } from '@storybook/react';
2
+ import IconButton from '@/Components/IconButton/IconButton';
3
+ import Input from './Input';
4
+
5
+ export default {
6
+ component: Input,
7
+ argTypes: {
8
+ type: {
9
+ control: 'inline-radio',
10
+ options: ['number', 'password', 'text'],
11
+ },
12
+ },
13
+ args: {
14
+ isDisabled: false,
15
+ isInvalid: false,
16
+ isLoading: false,
17
+ isReadOnly: false,
18
+ label: 'Input',
19
+ placeholder: 'Placeholder text',
20
+ type: 'text',
21
+ width: '400px',
22
+ },
23
+ } as ComponentMeta<typeof Input>;
24
+
25
+ export const WithProps = {
26
+ args: {
27
+ errorText: '',
28
+ helperText:
29
+ 'Inline help. Maecenas a turpis tortor. Nunc vitae libero tempor, ullamcorper purus quis, mattis tellus.',
30
+ label: 'Input',
31
+ },
32
+ };
33
+
34
+ export const WithElement = {
35
+ args: {
36
+ isDisabled: true,
37
+ label: 'With additional element (Like IconButton)',
38
+ rightElement: (
39
+ <IconButton aria-label="Copy to clipboard" borderLeftRadius="0" iconName="Duplicate" variant="secondary">
40
+ eee
41
+ </IconButton>
42
+ ),
43
+ value: '1234567890ABCDE',
44
+ },
45
+ };
46
+
47
+ export const WithIcon = {
48
+ args: {
49
+ label: 'With Icon on the left and/or right side',
50
+ leftIconName: 'Magnifier',
51
+ },
52
+ };
@@ -0,0 +1,38 @@
1
+ import { defineStyle } from '@chakra-ui/styled-system';
2
+
3
+ const InputTheme = defineStyle({
4
+ baseStyle: {
5
+ field: {
6
+ width: '100%',
7
+ padding: '0.6875rem',
8
+ background: 'neutral.100',
9
+ border: '1px solid',
10
+ borderColor: 'neutral.90',
11
+ borderRadius: '4',
12
+ boxShadow: 'inner',
13
+ outline: 0,
14
+ appearance: 'none',
15
+ transition: '200ms',
16
+ _placeholder: {
17
+ fontStyle: 'italic',
18
+ },
19
+ _disabled: {
20
+ background: 'neutral.93',
21
+ cursor: 'not-allowed',
22
+ },
23
+ _focusVisible: {
24
+ boxShadow: 'formFocus',
25
+ borderColor: 'purple.50',
26
+ },
27
+ _invalid: {
28
+ color: 'red.50',
29
+ borderColor: 'red.50',
30
+ },
31
+ },
32
+ leftElement: {
33
+ background: 'red',
34
+ },
35
+ },
36
+ });
37
+
38
+ export default InputTheme;
@@ -0,0 +1,133 @@
1
+ import { ReactNode, Ref } from 'react';
2
+ import {
3
+ FormControl,
4
+ FormControlProps,
5
+ FormErrorMessage,
6
+ Input as ChakraInput,
7
+ InputProps as ChakraInputProps,
8
+ forwardRef,
9
+ InputGroup,
10
+ InputLeftElement,
11
+ InputRightElement,
12
+ } from '@chakra-ui/react';
13
+ import Icon, { TypeIconName } from '../../Icon/Icon';
14
+ import FormLabel from '../FormLabel/FormLabel';
15
+ import FormHelperText from '../FormHelperText/FormHelperText';
16
+
17
+ type UsedFormControlProps = Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'>;
18
+ type UsedChakraInputProps = Pick<
19
+ ChakraInputProps,
20
+ | 'onBlur'
21
+ | 'onChange'
22
+ | 'role'
23
+ | 'name'
24
+ | 'type'
25
+ | 'value'
26
+ | 'autoComplete'
27
+ | 'autoFocus'
28
+ | 'max'
29
+ | 'maxLength'
30
+ | 'min'
31
+ | 'minLength'
32
+ | 'pattern'
33
+ | 'step'
34
+ >;
35
+ export interface InputProps extends UsedFormControlProps, UsedChakraInputProps {
36
+ 'data-testid'?: string;
37
+ errorText?: ReactNode;
38
+ isLoading?: boolean;
39
+ helperText?: ReactNode;
40
+ inputRef?: Ref<HTMLInputElement>;
41
+ label?: ReactNode;
42
+ leftIconName?: TypeIconName;
43
+ rightElement?: ReactNode;
44
+ rightIconName?: TypeIconName;
45
+ }
46
+
47
+ /**
48
+ * Input component is a component that is used to get user input in a text field.
49
+ */
50
+ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
51
+ const {
52
+ 'data-testid': dataTestid,
53
+ autoComplete,
54
+ autoFocus,
55
+ errorText,
56
+ helperText,
57
+ isDisabled,
58
+ inputRef,
59
+ isInvalid,
60
+ isLoading,
61
+ label,
62
+ leftIconName,
63
+ max,
64
+ maxLength,
65
+ min,
66
+ minLength,
67
+ pattern,
68
+ placeholder,
69
+ step,
70
+ onBlur,
71
+ onChange,
72
+ rightElement,
73
+ rightIconName,
74
+ name,
75
+ role,
76
+ type,
77
+ value,
78
+ ...rest
79
+ } = props;
80
+
81
+ const formControlProps = {
82
+ isDisabled: isDisabled || isLoading,
83
+ isInvalid: isInvalid || !!errorText,
84
+ ...rest,
85
+ ref,
86
+ };
87
+ const inputProps = {
88
+ autoComplete,
89
+ autoFocus,
90
+ 'data-testid': dataTestid,
91
+ onBlur,
92
+ onChange,
93
+ name,
94
+ max,
95
+ maxLength,
96
+ min,
97
+ minLength,
98
+ pattern,
99
+ placeholder,
100
+ ref: inputRef,
101
+ role,
102
+ step,
103
+ type,
104
+ value,
105
+ };
106
+ return (
107
+ <FormControl {...formControlProps}>
108
+ {label && <FormLabel>{label}</FormLabel>}
109
+ <InputGroup>
110
+ {leftIconName && (
111
+ <InputLeftElement margin="12px" pointerEvents="none">
112
+ <Icon name={leftIconName} />
113
+ </InputLeftElement>
114
+ )}
115
+ <ChakraInput
116
+ paddingLeft={leftIconName ? '43px' : '11px'}
117
+ paddingRight={rightIconName ? '43px' : '11px'}
118
+ {...inputProps}
119
+ />
120
+ {rightElement && <InputRightElement>{rightElement}</InputRightElement>}
121
+ {!rightElement && rightIconName && (
122
+ <InputRightElement margin="12px" pointerEvents="none">
123
+ <Icon name={rightIconName} />
124
+ </InputRightElement>
125
+ )}
126
+ </InputGroup>
127
+ {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
128
+ {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
129
+ </FormControl>
130
+ );
131
+ });
132
+
133
+ export default Input;
@@ -1,36 +1,11 @@
1
- import type { ComponentStyleConfig } from '@chakra-ui/theme';
1
+ import { defineStyle } from '@chakra-ui/styled-system';
2
+ import InputTheme from '../Input/Input.theme';
2
3
 
3
- const TextareaTheme: ComponentStyleConfig = {
4
+ const TextareaTheme = defineStyle({
4
5
  baseStyle: {
5
- width: '100%',
6
+ ...InputTheme.baseStyle?.field,
6
7
  minHeight: '96',
7
- padding: '16',
8
- background: 'neutral.100',
9
- border: '1px solid',
10
- borderColor: 'neutral.90',
11
- borderRadius: '4',
12
- boxShadow: 'inner',
13
- outline: 0,
14
- appearance: 'none',
15
- lineHeight: 'short',
16
- verticalAlign: 'top',
17
- transition: '200ms',
18
- _placeholder: {
19
- fontStyle: 'italic',
20
- },
21
- _disabled: {
22
- background: 'neutral.93',
23
- cursor: 'not-allowed',
24
- },
25
- _focusVisible: {
26
- boxShadow: 'formFocus',
27
- borderColor: 'purple.50',
28
- },
29
- _invalid: {
30
- color: 'red.50',
31
- borderColor: 'red.50',
32
- },
33
8
  },
34
- };
9
+ });
35
10
 
36
11
  export default TextareaTheme;
@@ -3,12 +3,12 @@ import {
3
3
  FormControl,
4
4
  FormControlProps,
5
5
  FormErrorMessage,
6
- FormHelperText,
7
- FormLabel,
8
6
  Textarea as ChakraTextarea,
9
7
  TextareaProps as ChakraTextareaProps,
10
8
  forwardRef,
11
9
  } from '@chakra-ui/react';
10
+ import FormLabel from '../FormLabel/FormLabel';
11
+ import FormHelperText from '../FormHelperText/FormHelperText';
12
12
 
13
13
  export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'> {
14
14
  'data-testid'?: string;
@@ -3,14 +3,14 @@ import {
3
3
  FormControl,
4
4
  FormControlProps,
5
5
  FormErrorMessage,
6
- FormHelperText,
7
- FormLabel,
8
6
  forwardRef,
9
7
  Select as ChakraSelect,
10
8
  SelectProps as ChakraSelectProps,
11
9
  Spinner,
12
10
  } from '@chakra-ui/react';
13
11
  import Icon from '../Icon/Icon';
12
+ import FormLabel from '../Form/FormLabel/FormLabel';
13
+ import FormHelperText from '../Form/FormHelperText/FormHelperText';
14
14
 
15
15
  export interface SelectProps extends Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'> {
16
16
  'data-testid'?: string;
@@ -3,8 +3,6 @@ import {
3
3
  FormControl,
4
4
  FormControlProps,
5
5
  FormErrorMessage,
6
- FormHelperText,
7
- FormLabel,
8
6
  Spinner,
9
7
  Switch,
10
8
  SwitchProps,
@@ -12,6 +10,8 @@ import {
12
10
  useMultiStyleConfig,
13
11
  } from '@chakra-ui/react';
14
12
  import Box from '../Box/Box';
13
+ import FormLabel from '../Form/FormLabel/FormLabel';
14
+ import FormHelperText from '../Form/FormHelperText/FormHelperText';
15
15
 
16
16
  export interface ToggleProps extends Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'> {
17
17
  'data-testid'?: string;
package/src/index.ts CHANGED
@@ -204,3 +204,12 @@ export { default as Textarea } from './Components/Form/Textarea/Textarea';
204
204
 
205
205
  export type { FadeProps } from './Components/Fade/Fade';
206
206
  export { default as Fade } from './Components/Fade/Fade';
207
+
208
+ export type { InputProps } from './Components/Form/Input/Input';
209
+ export { default as Input } from './Components/Form/Input/Input';
210
+
211
+ export type { FormLabelProps } from './Components/Form/FormLabel/FormLabel';
212
+ export { default as FormLabel } from './Components/Form/FormLabel/FormLabel';
213
+
214
+ export type { HelpTextProps as FormHelperTextProps } from './Components/Form/FormHelperText/FormHelperText';
215
+ export { default as FormHelperText } from './Components/Form/FormHelperText/FormHelperText';
package/src/old.ts CHANGED
@@ -18,21 +18,6 @@ export { default as DatePicker } from './Old/DatePicker/DatePicker';
18
18
  export type { Props as FlexProps } from './Old/Flex/Flex';
19
19
  export { default as Flex } from './Old/Flex/Flex';
20
20
 
21
- export type { Props as InputProps } from './Old/Input/Input';
22
- export { default as Input } from './Old/Input/Input';
23
-
24
- export type { Props as InputContainerProps } from './Old/Input/InputContainer';
25
- export { default as InputContainer } from './Old/Input/InputContainer';
26
-
27
- export type { Props as InputContentProps } from './Old/Input/InputContent';
28
- export { default as InputContent } from './Old/Input/InputContent';
29
-
30
- export type { Props as InputInlineHelpProps } from './Old/Input/InputInlineHelp';
31
- export { default as InputInlineHelp } from './Old/Input/InputInlineHelp';
32
-
33
- export type { Props as InputLabelProps } from './Old/Input/InputLabel';
34
- export { default as InputLabel } from './Old/Input/InputLabel';
35
-
36
21
  export type { Props as ProgressBarProps } from './Old/Progress/ProgressBar';
37
22
  export { default as ProgressBar } from './Old/Progress/ProgressBar';
38
23
 
package/src/theme.ts CHANGED
@@ -14,7 +14,7 @@ import List from './Components/List/List.theme';
14
14
  import Menu from './Components/Menu/Menu.theme';
15
15
  import Radio from './Components/Form/Radio/Radio.theme';
16
16
  import Select from './Components/Select/Select.theme';
17
- import Input from './Components/Input/Input.theme';
17
+ import Input from './Components/Form/Input/Input.theme';
18
18
  import Dropdown from './Components/Dropdown/Dropdown.theme';
19
19
  import Tabs from './Components/Tabs/Tabs.theme';
20
20
  import Text from './Components/Text/Text.theme';