forstok-ui-lib 1.0.8 → 1.0.9

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": "forstok-ui-lib",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Forstok UI Components Library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -0,0 +1,109 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ const getInputContainerStyled = css`
4
+ position: absolute;
5
+ opacity: 0;
6
+ cursor: pointer;
7
+ height: 0;
8
+ width: 0;
9
+ `
10
+ const arrowIconStyles = css`
11
+ padding-right: 18px;
12
+ i {
13
+ position: absolute;
14
+ right: 8px;
15
+ top: 50%;
16
+ margin-top: -10px;
17
+ }
18
+ `
19
+ const getCheckboxModifiedStyled = ({ $flow, $iconRight, disabled }:{ $flow?: string, $iconRight?: boolean, disabled: boolean }) => {
20
+ let style = ``;
21
+ if (disabled) {
22
+ style += `
23
+ cursor: default;
24
+ `
25
+ }
26
+ switch ($flow) {
27
+ case 'column':
28
+ style += `
29
+ display: inline-grid;
30
+ grid-auto-flow: column;
31
+ `
32
+ break
33
+ default:
34
+ style += `
35
+ display: grid;
36
+ grid-auto-flow: row;
37
+ `
38
+ break
39
+ }
40
+ if ($iconRight) {
41
+ style += arrowIconStyles
42
+ }
43
+ return style;
44
+ }
45
+ const getCheckmarkPropsModifiedStyled = ({ $isError }:{ $isError?: boolean }) => {
46
+ let style = ``;
47
+ if ($isError) {
48
+ style += `
49
+ border:1px solid #fc5c64;
50
+ `
51
+ }
52
+ return style;
53
+ }
54
+
55
+ export const CheckmarkContainer = styled.span<{ $isError?: boolean }>`
56
+ position: absolute;
57
+ left: 0;
58
+ height: 14px;
59
+ width: 14px;
60
+ background-color: var(--cl-clr-bg);
61
+ border: 1px solid var(--ck-clr-ln);
62
+ border-radius: var(--ter-rd);
63
+ &:after {
64
+ content: "";
65
+ position: absolute;
66
+ display: none;
67
+ left: -1px;
68
+ top: -1px;
69
+ width: 16px;
70
+ height: 16px;
71
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E");
72
+ border-radius: var(--ter-rd);
73
+ }
74
+ ${getCheckmarkPropsModifiedStyled}
75
+ `
76
+ export const CheckboxContainer = styled.label<{ $flow?: string, $iconRight?: boolean, disabled: boolean }>`
77
+ grid-gap: 6px;
78
+ position: relative;
79
+ cursor: pointer;
80
+ user-select: none;
81
+ align-items: center;
82
+ padding-left: 24px;
83
+ > input {
84
+ ${getInputContainerStyled}
85
+ }
86
+ input:checked ~ span,
87
+ input.checked ~ span {
88
+ background-color: var(--ck-clr-bg__act);
89
+ border: 0;
90
+ }
91
+ input:checked ~ span:after,
92
+ input.checked ~ span:after {
93
+ display: grid;
94
+ }
95
+ @media (min-width: 425px) {
96
+ padding-left: 24px;
97
+ }
98
+ ${getCheckboxModifiedStyled}
99
+ `
100
+ export const InputContainer = styled.input`
101
+ &:disabled {
102
+ cursor: default;
103
+ & + span {
104
+ background-color: var(--mt-clr-bg);
105
+ border-color: var(--pri-clr-ln);
106
+ }
107
+ }
108
+ ${getInputContainerStyled}
109
+ `
@@ -0,0 +1,68 @@
1
+ import { useRef, useEffect, useState, type PropsWithChildren, type InputHTMLAttributes, type ChangeEvent } from 'react';
2
+ import InputComponent from '../input/input';
3
+ import { CheckboxContainer, CheckmarkContainer } from './checkbox.styles';
4
+ import type { TState } from '../../typeds/base.typed';
5
+
6
+ type TInput = InputHTMLAttributes<HTMLInputElement> & {
7
+ evChange?: (e: ChangeEvent<HTMLInputElement>) => void
8
+ $flow?: string
9
+ extendKey?: string | null
10
+ extendClass?: string
11
+ reset?: boolean
12
+ setReset?: TState<boolean>
13
+ isForceUpdate?: boolean
14
+ setForceUpdate?: (value: boolean) => void | TState<boolean>
15
+ $isError?: boolean
16
+ $iconRight?: boolean
17
+ 'data-qa-id'?: string
18
+ };
19
+
20
+ const CheckboxComponent = ({ id, name, children, $flow, extendKey, extendClass, reset, setReset, isForceUpdate, setForceUpdate, evChange, $isError, $iconRight, ...props }:PropsWithChildren<TInput>) => {
21
+ const { disabled, defaultChecked } = props;
22
+ const [inputChecked, evInputChecked] = useState<boolean>(defaultChecked||false);
23
+ const checkboxRef = useRef<HTMLLabelElement | null>(null);
24
+
25
+ useEffect(() => {
26
+ if (isForceUpdate) {
27
+ evInputChecked(defaultChecked||false);
28
+ setForceUpdate && setForceUpdate(false);
29
+ }
30
+ if (reset) {
31
+ evInputChecked(false);
32
+ setReset && setReset(false);
33
+ }
34
+ }, [reset, setReset, isForceUpdate, setForceUpdate, defaultChecked]);
35
+
36
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
37
+ evInputChecked(e.target.checked);
38
+ evChange && evChange(e);
39
+ };
40
+
41
+ let parseProps = {...props};
42
+ delete parseProps.defaultChecked;
43
+
44
+ return (
45
+ <CheckboxContainer
46
+ $flow={$flow}
47
+ $iconRight={$iconRight}
48
+ ref={checkboxRef}
49
+ htmlFor={id}
50
+ disabled={disabled || false} >
51
+ {children}
52
+ <InputComponent
53
+ id={id}
54
+ type='checkbox'
55
+ checked={inputChecked}
56
+ name={name}
57
+ evChange={handleChange}
58
+ {...extendClass && { className: extendClass }}
59
+ {...extendKey !== '' && { 'data-key': extendKey }}
60
+ {...props} />
61
+ <CheckmarkContainer
62
+ $isError={$isError}
63
+ {...props['data-qa-id'] && { 'data-qa-id': props['data-qa-id'] }} />
64
+ </CheckboxContainer>
65
+ );
66
+ };
67
+
68
+ export default CheckboxComponent;
@@ -21,8 +21,34 @@ type TLinkBase = {
21
21
 
22
22
  const LinkComponent = ({ children, mode, $activated=false, href, $elipsis=false, $shadow=false, disabled=false, ...props }: TLinkBase) => {
23
23
  const { onClick } = props
24
- return (
25
- href ? <AnchorLinkContainer className='_refLink' mode={mode} $activated={$activated ? true : false} $elipsis={$elipsis ? true : false} $shadow={$shadow ? true : false} disabled={disabled ? true : false} href={href} {...props}>{children}</AnchorLinkContainer> : <ElLinkContainer className='_refLink' mode={mode} $activated={$activated ? true : false} $elipsis={$elipsis ? true : false} $shadow={$shadow ? true : false} disabled={disabled ? true : false} onClick={onClick} {...props}>{children}</ElLinkContainer>)
24
+ return (
25
+ href ? (
26
+ <AnchorLinkContainer
27
+ className='_refLink'
28
+ mode={mode}
29
+ $activated={$activated}
30
+ $elipsis={$elipsis}
31
+ $shadow={$shadow}
32
+ disabled={disabled}
33
+ href={href}
34
+ {...props}
35
+ >
36
+ {children}
37
+ </AnchorLinkContainer>
38
+ ) : (
39
+ <ElLinkContainer
40
+ className='_refLink'
41
+ mode={mode}
42
+ $activated={$activated}
43
+ $elipsis={$elipsis}
44
+ $shadow={$shadow}
45
+ disabled={disabled}
46
+ onClick={onClick}
47
+ {...props}
48
+ >
49
+ {children}
50
+ </ElLinkContainer>
51
+ )
26
52
  );
27
53
  };
28
54