@loja-integrada/admin-components 0.11.0 → 0.12.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@loja-integrada/admin-components",
3
- "version": "0.11.0",
3
+ "version": "0.12.3",
4
4
  "author": "Loja Integrada Front-End Team",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -64,6 +64,9 @@ describe('Button tests', () => {
64
64
 
65
65
  mount(<Default variant="danger" />)
66
66
  cy.get('button').should('have.class', 'bg-danger text-base-1')
67
+
68
+ mount(<Default variant="outlineSecondary" />)
69
+ cy.get('button').should('have.class', 'bg-transparent text-primary border border-primary')
67
70
  })
68
71
 
69
72
  })
@@ -5,6 +5,7 @@ import { Icon, IconProps } from '../../Icons/Icon'
5
5
  const listOfStylesHover = {
6
6
  primary: `hover:bg-primary-dark`,
7
7
  secondary: `hover:bg-secondary-dark`,
8
+ outlineSecondary: `hover:bg-primary-light`,
8
9
  tertiary: `hover:bg-tertiary-dark`,
9
10
  info: `hover:bg-secondary-bold`,
10
11
  warning: `hover:bg-warning-dark`,
@@ -15,6 +16,7 @@ const listOfStylesHover = {
15
16
  const listOfStylesActive = {
16
17
  primary: `active:bg-primary-bold`,
17
18
  secondary: `active:shadow-inner`,
19
+ outlineSecondary: `active:shadow-inner active:bg-base-1`,
18
20
  tertiary: `active:bg-tertiary-bold`,
19
21
  warning: `active:bg-warning-bold`,
20
22
  danger: `hover:bg-danger-bold`,
@@ -24,6 +26,7 @@ const listOfStylesActive = {
24
26
  const listOfStylesFocus = {
25
27
  primary: `focus:ring-1 focus:ring-primary-dark focus:ring-opacity-50`,
26
28
  secondary: `focus:ring focus:ring-focus`,
29
+ outlineSecondary: `focus:ring-2 focus:ring-focus focus:ring-offset-1`,
27
30
  danger: `focus:ring-1 focus:ring-danger-dark`,
28
31
  outline: `focus:ring-2 focus:ring-focus focus:ring-offset-1`,
29
32
  onlyText: `focus:bg-base-1`,
@@ -31,6 +34,7 @@ const listOfStylesFocus = {
31
34
  const listOfStyles = {
32
35
  primary: `bg-primary text-base-1 ${listOfStylesHover['primary']} ${listOfStylesActive['primary']} ${listOfStylesFocus['primary']}`,
33
36
  secondary: `bg-secondary text-primary ${listOfStylesHover['secondary']} ${listOfStylesActive['secondary']}`,
37
+ outlineSecondary: `bg-transparent text-primary border border-primary ${listOfStylesHover['outlineSecondary']} ${listOfStylesActive['outlineSecondary']} ${listOfStylesFocus['outlineSecondary']}`,
34
38
  tertiary: `bg-inverted-2 text-on-primary ${listOfStylesHover['tertiary']} ${listOfStylesActive['tertiary']}`,
35
39
  info: `bg-secondary-dark text-base-1 ${listOfStylesHover['info']}`,
36
40
  warning: `bg-warning text-on-base ${listOfStylesHover['warning']} ${listOfStylesActive['warning']}`,
@@ -43,6 +47,7 @@ const defaultDisabledStyle = `bg-base-3 cursor-default text-on-base-2 shadow-non
43
47
  const listOfStylesDisabled = {
44
48
  primary: defaultDisabledStyle,
45
49
  secondary: `bg-base-2 cursor-default text-card-stroke shadow-none ring-0 border-0 `,
50
+ outlineSecondary: `bg-base-2 cursor-default text-card-stroke shadow-none ring-0 border-0 `,
46
51
  tertiary: defaultDisabledStyle,
47
52
  info: defaultDisabledStyle,
48
53
  warning: defaultDisabledStyle,
@@ -68,6 +73,10 @@ const ButtonType = React.forwardRef(
68
73
  {children}
69
74
  </a>
70
75
  )
76
+ if (!props.type) {
77
+ // Default to button when missing type
78
+ props.type = 'button'
79
+ }
71
80
  return (
72
81
  <button {...props} ref={ref}>
73
82
  {children}
@@ -150,6 +159,7 @@ export interface ButtonProps extends ButtonAnchorProps {
150
159
  variant?:
151
160
  | 'primary'
152
161
  | 'secondary'
162
+ | 'outlineSecondary'
153
163
  | 'tertiary'
154
164
  | 'info'
155
165
  | 'warning'
@@ -166,7 +166,7 @@ const CustomSingleValue = (
166
166
  ) => (
167
167
  <SingleValue
168
168
  {...props}
169
- className={`text-f6 tracking-4 text-inverted-2 text-sm truncate ${variantValueClasses[variant]}`}
169
+ className={`text-f6 tracking-4 text-on-base text-sm truncate ${variantValueClasses[variant]}`}
170
170
  />
171
171
  )
172
172
 
@@ -23,8 +23,8 @@ export const formatValuePatterns = {
23
23
  },
24
24
  onlyText: {
25
25
  mask: (rawValue: any) => {
26
- const onlyText = rawValue.replace(/[^a-zA-ZÀ-ú'~0-9\s]/g, '').split('')
27
- return onlyText.map(() => /[a-zA-ZÀ-ú'~´`^0-9\s]/g)
26
+ const onlyText = rawValue.replace(/[^a-zA-ZÀ-ú'˜0-9\]/g, '').split('')
27
+ return onlyText.map(() => /[a-zA-ZÀ-ú'˜`´^0-9\]/g)
28
28
  },
29
29
  },
30
30
  date: {
@@ -44,7 +44,7 @@ export const SelectComponent = (
44
44
  } else {
45
45
  inputClass = `${inputClasses} ${selectClasses} ${variantClasses[variant]}`
46
46
  if (disabled) {
47
- inputClass += ` ${defaultBorderClasses} ${inputContainerDisabledClasses}`
47
+ inputClass += ` ${defaultBorderClasses} ${inputContainerDisabledClasses} opacity-100`
48
48
  } else if (hasErrorState) {
49
49
  inputClass += ` ${errorBorderClasses}`
50
50
  } else {
@@ -7,6 +7,9 @@ const ToggleComponent = (
7
7
  const inputId = id || name
8
8
  const [isChecked, setIsChecked] = React.useState(checked || false)
9
9
 
10
+ const toggleStatusText = disabled ? 'disabled' : 'enabled'
11
+ const toggleCheckText = isChecked ? 'checked' : 'unchecked'
12
+
10
13
  React.useEffect(() => {
11
14
  setIsChecked(!!checked)
12
15
  }, [checked])
@@ -17,18 +20,36 @@ const ToggleComponent = (
17
20
  onChange && onChange(event)
18
21
  }
19
22
 
23
+ const toggleClasses = {
24
+ background: {
25
+ checked: {
26
+ enabled: 'bg-primary border-primary',
27
+ disabled: 'bg-base-3 border-card-stroke',
28
+ },
29
+ unchecked: {
30
+ enabled: 'bg-base-1 border-card-stroke',
31
+ disabled: 'bg-base-3 border-card-stroke',
32
+ },
33
+ },
34
+ circle: {
35
+ checked: {
36
+ enabled: 'translate-x-full ml-px bg-base-1',
37
+ disabled: 'translate-x-full ml-px bg-base-1',
38
+ },
39
+ unchecked: {
40
+ enabled: 'translate-x-0 bg-inverted-2',
41
+ disabled: 'translate-x-0 bg-base-1',
42
+ },
43
+ },
44
+ }
45
+
20
46
  const toggleContainerDisabledClasses = `${
21
47
  disabled ? 'pointer-events-none' : ''
22
48
  } relative`
23
49
 
24
- const toggleBackgroundClasses = `block border border-card-stroke w-[53px] h-8 rounded-full
25
- ${disabled ? ' bg-base-3' : ' bg-base-1'} `
50
+ const toggleBackgroundClasses = `block border w-[53px] h-8 rounded-full ${toggleClasses.background[toggleCheckText][toggleStatusText]} transition`
26
51
 
27
- const toggleCircleClasses = `transform ${
28
- !isChecked
29
- ? 'translate-x-0 bg-inverted-2'
30
- : 'translate-x-full ml-px ' + (disabled ? 'bg-base-1' : 'bg-primary')
31
- } absolute left-[6px] top-[6px] w-5 h-5 rounded-full transition`
52
+ const toggleCircleClasses = `transform ${toggleClasses.circle[toggleCheckText][toggleStatusText]} absolute left-[6px] top-[6px] w-5 h-5 rounded-full transition`
32
53
 
33
54
  const toggleLabelClasses = `ml-2 text-inverted-1 text-f6 tracking-4 label`
34
55
 
@@ -55,8 +76,8 @@ const ToggleComponent = (
55
76
  )
56
77
  }
57
78
 
58
- const ToggleWithFowardRef = React.forwardRef(ToggleComponent)
59
- export const Toggle = React.memo(ToggleWithFowardRef)
79
+ const ToggleWithForwardRef = React.forwardRef(ToggleComponent)
80
+ export const Toggle = React.memo(ToggleWithForwardRef)
60
81
 
61
82
  export interface ToggleProps
62
83
  extends React.InputHTMLAttributes<HTMLInputElement> {
@@ -21,7 +21,7 @@ export default {
21
21
  } as Meta
22
22
 
23
23
  const Template: Story<TooltipProps> = args => (
24
- <div className="my-10 flex justify-center">
24
+ <div className="absolute bg-base-2 inset-0 flex items-center justify-center">
25
25
  <Tooltip {...args}>
26
26
  <a href="#">
27
27
  <Icon icon="eye" />
@@ -26,7 +26,7 @@ const TooltipComponent = (props: TooltipProps) => {
26
26
  }
27
27
 
28
28
  return (
29
- <Tippy
29
+ <StyledTooltipComponent
30
30
  {...computedProps}
31
31
  appendTo={props?.appendTo || 'parent'}
32
32
  hideOnClick={props?.hideOnClick || false}
@@ -35,15 +35,29 @@ const TooltipComponent = (props: TooltipProps) => {
35
35
  duration={props?.duration || 150}
36
36
  placement={window?.innerWidth < 1024 ? 'top' : props?.placement || 'top'}
37
37
  interactive={props?.interactive || false}
38
+ theme={props?.theme || 'dark'}
38
39
  />
39
40
  )
40
41
  }
41
42
 
42
- const styledTooltipComponent = styled(TooltipComponent)`
43
- --bg-color: #20221b;
43
+ const theme: Record<string, Record<string, string>> = {
44
+ light: {
45
+ background: '#fff',
46
+ color: '#371E56',
47
+ },
48
+ dark: {
49
+ background: '#371E56',
50
+ color: '#fff',
51
+ },
52
+ }
53
+
54
+ const StyledTooltipComponent = styled(Tippy)<{
55
+ theme: string
56
+ }>`
57
+ --bg-color: ${(props) => theme[props.theme].background};
44
58
  position: relative;
45
59
  background-color: var(--bg-color);
46
- color: #fff;
60
+ color: ${(props) => theme[props.theme].color};
47
61
  border-radius: 3px;
48
62
  font-size: 12px;
49
63
  letter-spacing: -0.4px;
@@ -129,7 +143,7 @@ const styledTooltipComponent = styled(TooltipComponent)`
129
143
  }
130
144
  `
131
145
 
132
- export const Tooltip = React.memo(styledTooltipComponent)
146
+ export const Tooltip = React.memo(TooltipComponent)
133
147
 
134
148
  export interface TooltipProps extends TippyProps {
135
149
  /** Tooltip append
@@ -160,4 +174,8 @@ export interface TooltipProps extends TippyProps {
160
174
  * @default false
161
175
  * */
162
176
  interactive?: TippyProps['interactive']
177
+ /** Tooltip theme
178
+ * @default dark
179
+ * */
180
+ theme?: 'light' | 'dark'
163
181
  }
@@ -59,6 +59,7 @@ const ActionBarComponent = ({ onlyMobile, children }: ActionBarProps) => {
59
59
  (props?.loading ? ' pointer-events-none' : '')
60
60
  }
61
61
  onClick={props?.onClick}
62
+ type={props?.type || 'button'}
62
63
  >
63
64
  {props?.loading ? (
64
65
  <Icon icon="loading" className="p-px" />