forstok-ui-lib 1.0.7 → 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.7",
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;
@@ -1,4 +1,3 @@
1
- import { Link } from 'react-router-dom';
2
1
  import styled, { css } from 'styled-components';
3
2
  import { multiElipsis } from '../../assets/stylesheets/bases.styles';
4
3
 
@@ -145,14 +144,6 @@ const getLinkModifiedStyled = ({ mode, $elipsis, $activated, $shadow, disabled }
145
144
  return style;
146
145
  }
147
146
 
148
- export const LinkContainer = styled(Link)<{ mode?: string, $elipsis: boolean, $activated: boolean, $shadow: boolean, disabled: boolean }>`
149
- &._refHoverLink {
150
- padding: 3px 0px 0px 6px;
151
- position: relative;
152
- top: -3px;
153
- }
154
- ${getLinkModifiedStyled}
155
- `
156
147
  export const AnchorLinkContainer = styled.a<{ mode?: string, $elipsis: boolean, $activated: boolean, $shadow: boolean, disabled: boolean }>`
157
148
  ${getLinkModifiedStyled}
158
149
  `
@@ -1,7 +1,5 @@
1
1
  import type { AnchorHTMLAttributes, ReactNode, MouseEvent, HTMLAttributes } from 'react';
2
2
  import { AnchorLinkContainer, ElLinkContainer } from './link.styles';
3
- import LinkRouteComponent from './link_route';
4
- import type { Path } from 'react-router-dom';
5
3
 
6
4
  type TLinkBase = {
7
5
  children: ReactNode
@@ -13,25 +11,44 @@ type TLinkBase = {
13
11
  } & (
14
12
  (AnchorHTMLAttributes<HTMLAnchorElement> & {
15
13
  href?: string
16
- to?: undefined
17
- onClick?: (e: MouseEvent<HTMLAnchorElement>) => void
18
- }) |
19
- (AnchorHTMLAttributes<HTMLAnchorElement> & {
20
- href?: undefined
21
- to: string | Partial<Path>
22
14
  onClick?: (e: MouseEvent<HTMLAnchorElement>) => void
23
15
  }) |
24
16
  (HTMLAttributes<HTMLSpanElement> & {
25
17
  href?: undefined
26
- to?: undefined
27
18
  onClick?: (e: MouseEvent<HTMLSpanElement>) => void
28
19
  })
29
20
  );
30
21
 
31
- const LinkComponent = ({ children, mode, $activated=false, href, to, $elipsis=false, $shadow=false, disabled=false, ...props }: TLinkBase) => {
22
+ const LinkComponent = ({ children, mode, $activated=false, href, $elipsis=false, $shadow=false, disabled=false, ...props }: TLinkBase) => {
32
23
  const { onClick } = props
33
- return (
34
- 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> : (to ? <LinkRouteComponent to={to} className='_refLink' mode={mode} $activated={$activated && true} $elipsis={$elipsis ? true : false} $shadow={$shadow ? true : false} disabled={disabled ? true : false} {...props}>{children}</LinkRouteComponent> : <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
+ )
35
52
  );
36
53
  };
37
54
 
@@ -1,22 +0,0 @@
1
- import type { ReactNode, AnchorHTMLAttributes } from 'react';
2
- import { BrowserRouter as Router } from 'react-router-dom';
3
- import type { LinkProps, Path } from 'react-router-dom';
4
- import { LinkContainer } from './link.styles';
5
-
6
- type TLinkBase = {
7
- children: ReactNode
8
- mode?: string
9
- $activated: boolean
10
- $elipsis: boolean
11
- $shadow: boolean
12
- disabled: boolean
13
- to: string | Partial<Path>
14
- };
15
-
16
- type TLink = LinkProps & AnchorHTMLAttributes<HTMLAnchorElement> & TLinkBase;
17
-
18
- const LinkRouteComponent = ({ children, mode, $activated, $elipsis, to, $shadow, disabled, ...props }: TLink) => {
19
- return <Router><LinkContainer className='_refLink' to={to} mode={mode} $activated={$activated ? true : false} $elipsis={$elipsis ? true : false} $shadow={$shadow ? true : false} disabled={disabled ? true : false} {...props}>{children}</LinkContainer></Router>;
20
- };
21
-
22
- export default LinkRouteComponent;