@platformatic/ui-components 0.7.34 → 0.8.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": "@platformatic/ui-components",
3
3
  "description": "Platformatic UI Components",
4
- "version": "0.7.34",
4
+ "version": "0.8.0",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -37,6 +37,7 @@ function Button ({
37
37
  ...rest
38
38
  }) {
39
39
  let buttonClassName = textClass
40
+ let tmpBorderedClassName = ''
40
41
  buttonClassName += ` ${styles.button} ${styles['color-' + color]} `
41
42
  let contentClassName = `${styles.content} `
42
43
  if (paddingClass) {
@@ -45,10 +46,10 @@ function Button ({
45
46
  contentClassName += `${styles['button-' + size]} `
46
47
  }
47
48
  if (disabled) {
48
- buttonClassName += ' ' + commonStyles[`bordered--${color}-30`]
49
+ tmpBorderedClassName = commonStyles[`bordered--${color}-30`]
49
50
  buttonClassName += ` ${styles.disabled}`
50
51
  } else {
51
- buttonClassName += bordered ? commonStyles[`bordered--${color}-100`] : ''
52
+ tmpBorderedClassName = bordered ? commonStyles[`bordered--${color}-70`] : ''
52
53
  }
53
54
  if (!bordered) buttonClassName += ` ${styles['no-border']}`
54
55
  if (fullWidth) {
@@ -58,10 +59,14 @@ function Button ({
58
59
  const [hover, setHover] = useState(false)
59
60
  const [inactive, setInactive] = useState(false)
60
61
  const [backgroundClassName, setBackgroundClassName] = useState(restClassName())
62
+ const [borderedClassName, setBorderedClassName] = useState(tmpBorderedClassName)
61
63
 
62
64
  useEffect(() => {
63
65
  if (!disabled) {
64
66
  if (hover) {
67
+ if (bordered) {
68
+ setBorderedClassName(commonStyles[`bordered--${color}-100`])
69
+ }
65
70
  switch (hoverEffect) {
66
71
  case DULLS_BACKGROUND_COLOR:
67
72
  setBackgroundClassName(restClassName() + ' ' + commonStyles[`hover-${DULLS_BACKGROUND_COLOR}-${color}`])
@@ -89,6 +94,13 @@ function Button ({
89
94
  } else {
90
95
  setBackgroundClassName(restClassName())
91
96
  }
97
+ if (bordered) {
98
+ setBorderedClassName(commonStyles[`bordered--${color}-70`])
99
+ }
100
+ }
101
+ } else {
102
+ if (bordered) {
103
+ setBorderedClassName(commonStyles[`bordered--${color}-30`])
92
104
  }
93
105
  }
94
106
  }, [disabled, hover, hoverEffect])
@@ -101,7 +113,7 @@ function Button ({
101
113
  }
102
114
 
103
115
  return (
104
- <button className={`${buttonClassName} ${restClassName()}`} disabled={disabled} alt={label} {...rest} onMouseLeave={() => setHover(false)} onMouseOver={() => setHover(true)}>
116
+ <button className={`${buttonClassName} ${restClassName()} ${borderedClassName}`} disabled={disabled} alt={label} {...rest} onMouseLeave={() => setHover(false)} onMouseOver={() => setHover(true)}>
105
117
  <div className={`${contentClassName} ${backgroundClassName}`}>
106
118
  {platformaticIcon ? <PlatformaticIcon key='left' iconName={platformaticIcon.iconName} color={platformaticIcon.color} data-testid='button-icon' onClick={null} inactive={inactive} /> : null}
107
119
  <span className={styles.label}>{label}</span>
@@ -2,14 +2,16 @@
2
2
  import React from 'react'
3
3
  import PropTypes from 'prop-types'
4
4
  import styles from './Checkbox.module.css'
5
- import { MAIN_DARK_BLUE, RICH_BLACK, WHITE } from './constants'
5
+ import { MAIN_DARK_BLUE, MEDIUM, RICH_BLACK, SMALL, WHITE } from './constants'
6
6
  function Checkbox ({
7
7
  disabled = false,
8
8
  color = MAIN_DARK_BLUE,
9
+ size = MEDIUM,
9
10
  ...rest
10
11
  }) {
11
- let className = `${styles.checkbox} `
12
- className += styles[`checkbox--${color}`]
12
+ let className = `${styles.checkbox}`
13
+ className += ' ' + styles[`checkbox--${size}`]
14
+ className += ' ' + styles[`checkbox--${color}`]
13
15
  if (disabled) className += ` ${styles.disabled}`
14
16
  return (
15
17
  <input type='checkbox' className={className} disabled={disabled} {...rest} />
@@ -24,7 +26,11 @@ Checkbox.propTypes = {
24
26
  /**
25
27
  * color
26
28
  */
27
- color: PropTypes.oneOf([WHITE, MAIN_DARK_BLUE, RICH_BLACK])
29
+ color: PropTypes.oneOf([WHITE, MAIN_DARK_BLUE, RICH_BLACK]),
30
+ /**
31
+ * size
32
+ */
33
+ size: PropTypes.oneOf([SMALL, MEDIUM])
28
34
  }
29
35
 
30
36
  export default Checkbox
@@ -1,8 +1,16 @@
1
1
  .checkbox {
2
- @apply border border-solid p-2 rounded-sm relative inline-block h-2 w-2 m-0;
2
+ @apply border border-solid rounded-sm relative inline-block m-0;
3
3
  -webkit-appearance: none;
4
4
  }
5
5
 
6
+ .checkbox--medium {
7
+ @apply p-2 h-2 w-2;
8
+ }
9
+
10
+ .checkbox--small {
11
+ @apply p-[5px] h-[10px] w-[10px];
12
+ }
13
+
6
14
  .checkbox--main-dark-blue {
7
15
  @apply border-light-green bg-main-dark-blue
8
16
  }
@@ -16,14 +24,20 @@
16
24
  .checkbox--white:checked {
17
25
  @apply bg-white text-rich-black;
18
26
  }
19
- .checkbox--main-dark-blue:checked:after,
20
- .checkbox--rich-black:checked:after {
27
+ .checkbox--medium.checkbox--main-dark-blue:checked:after,
28
+ .checkbox--medium.checkbox--rich-black:checked:after {
21
29
  @apply absolute h-full w-full;
22
30
  top: 1px;
23
31
  left: 1.5px;
24
32
  content: url('data:image/svg+xml,%3Csvg%20width%3D%2213%22%20height%3D%229%22%20viewBox%3D%220%200%2013%209%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M1%204L5%208L12%201%22%20stroke%3D%22white%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E');
25
33
  }
26
-
34
+ .checkbox--small.checkbox--main-dark-blue:checked:after,
35
+ .checkbox--small.checkbox--rich-black:checked:after {
36
+ @apply absolute h-full w-full;
37
+ top: 1px;
38
+ left: 1px;
39
+ content: url('data:image/svg+xml,%3Csvg%20width%3D%2211%22%20height%3D%228%22%20viewBox%3D%220%200%2011%208%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%20%3Cpath%20d%3D%22M1.25%203.5L4.25%206.5L9.5%201.25%22%20stroke%3D%22white%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%20%3C%2Fsvg%3E');
40
+ }
27
41
  .disabled {
28
42
  @apply border-white;
29
43
  }
@@ -34,9 +48,16 @@
34
48
  .checkbox--rich-black:checked {
35
49
  @apply bg-white text-rich-black;
36
50
  }
37
- .checkbox--white:checked:after {
51
+ .checkbox--medium.checkbox--white:checked:after {
38
52
  @apply absolute h-full w-full;
39
53
  top: 1px;
40
54
  left: 1.5px;
41
55
  content: url('data:image/svg+xml,%3Csvg%20width=%2213%22%20height=%229%22%20viewBox=%220%200%2013%209%22%20fill=%22none%22%20xmlns=%22http://www.w3.org/2000/svg%22%3E%3Cpath%20d=%22M1%204L5%208L12%201%22%20stroke%3D%22%2300050B%22%20stroke-width=%222%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22/%3E%3C/svg%3E');
42
56
  }
57
+
58
+ .checkbox--small.checkbox--white:checked:after {
59
+ @apply absolute h-full w-full;
60
+ top: -2px;
61
+ left: 0px;
62
+ content: url('data:image/svg+xml,%3Csvg%20width%3D%2211%22%20height%3D%228%22%20viewBox%3D%220%200%2011%208%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%20%3Cpath%20d%3D%22M1.25%203.5L4.25%206.5L9.5%201.25%22%20stroke%3D%22%2300050B%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%20%3C%2Fsvg%3E');
63
+ }
@@ -3,6 +3,7 @@ import React from 'react'
3
3
  import PropTypes from 'prop-types'
4
4
  import styles from './ToggleSwitch.module.css'
5
5
  import commonStyles from '../Common.module.css'
6
+ import { MEDIUM, SMALL } from '../constants'
6
7
 
7
8
  function ToggleSwitch ({
8
9
  name = '',
@@ -12,19 +13,23 @@ function ToggleSwitch ({
12
13
  errorMessageTextClassName = '',
13
14
  onChange = () => {},
14
15
  checked = false,
15
- disabled = false
16
+ disabled = false,
17
+ size = MEDIUM
16
18
  }) {
17
19
  let className = `${styles.switch} `
20
+ className += styles[`switch--${size}`] + ' '
18
21
  if (disabled) className += styles.disabled
19
22
  const styleLabel = labelClassName || styles.defaultLabel
20
23
  const errorMessageClassName = errorMessageTextClassName || commonStyles['error-message']
24
+ let sliderClassName = `${styles.slider} ${styles.round} `
25
+ sliderClassName += styles[`slider--${size}`]
21
26
 
22
27
  return (
23
28
  <>
24
29
  <div className={styles.container}>
25
30
  <label className={className}>
26
31
  <input type='checkbox' name={name} onChange={onChange} checked={checked} disabled={disabled} />
27
- <span className={`${styles.slider} ${styles.round}`} />
32
+ <span className={sliderClassName} />
28
33
  </label>
29
34
  <span className={styleLabel}>{label}</span>
30
35
  </div>
@@ -65,7 +70,11 @@ ToggleSwitch.propTypes = {
65
70
  /**
66
71
  * labelClassName
67
72
  */
68
- labelClassName: PropTypes.string
73
+ labelClassName: PropTypes.string,
74
+ /**
75
+ * size
76
+ */
77
+ size: PropTypes.oneOf([SMALL, MEDIUM])
69
78
 
70
79
  }
71
80
 
@@ -2,7 +2,13 @@
2
2
  @apply flex w-full h-10 items-center gap-x-2;
3
3
  }
4
4
  .switch {
5
- @apply relative inline-block w-[50px] h-[24px] cursor-pointer;
5
+ @apply relative inline-block cursor-pointer;
6
+ }
7
+ .switch--medium {
8
+ @apply w-[50px] h-[24px]
9
+ }
10
+ .switch--small {
11
+ @apply w-[30px] h-[16px]
6
12
  }
7
13
  .switch input {
8
14
  @apply opacity-0 w-0 h-0;
@@ -13,26 +19,40 @@
13
19
  -webkit-transition: .4s;
14
20
  transition: .4s;
15
21
  }
22
+
16
23
  .defaultLabel {
17
24
  @apply px-2 text-xs font-normal text-main-dark-blue;
18
25
  }
19
- .slider:before {
20
- @apply absolute h-4 w-4 left-[4px] bottom-[4px] bg-white;
26
+ .slider--small:before,
27
+ .slider--medium:before {
21
28
  content: "";
22
29
  -webkit-transition: .4s;
23
30
  transition: .4s;
24
31
  }
25
32
 
33
+ .slider--medium:before {
34
+ @apply absolute h-[22px] w-[22px] left-[1px] bottom-[1px] bg-white;
35
+ }
36
+ .slider--small:before{
37
+ @apply absolute h-[14px] w-[14px] left-[1px] bottom-[1px] bg-white;
38
+ }
39
+
26
40
  input:checked + .slider {
27
41
  @apply bg-main-green;
28
42
  }
29
43
 
30
- input:checked + .slider:before {
44
+ input:checked + .slider--medium:before {
31
45
  -webkit-transform: translateX(26px);
32
46
  -ms-transform: translateX(26px);
33
47
  transform: translateX(26px);
34
48
  }
35
49
 
50
+ input:checked + .slider--small:before {
51
+ -webkit-transform: translateX(14px);
52
+ -ms-transform: translateX(14px);
53
+ transform: translateX(14px);
54
+ }
55
+
36
56
  /* Rounded sliders */
37
57
  .slider.round {
38
58
  border-radius: 100px;
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  import Checkbox from '../components/Checkbox'
3
- import { WHITE } from '../components/constants'
3
+ import { MEDIUM, SMALL, WHITE } from '../components/constants'
4
4
  const divStyle = {
5
5
  width: '100%',
6
6
  height: 'auto',
@@ -24,6 +24,10 @@ export default {
24
24
  },
25
25
  disabled: {
26
26
  type: 'boolean'
27
+ },
28
+ size: {
29
+ type: 'radio',
30
+ options: [SMALL, MEDIUM]
27
31
  }
28
32
  }
29
33
  }