@codeleap/web 1.0.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/.eslintignore +2 -0
- package/.eslintrc.js +3 -0
- package/.turbo/turbo-build.log +1 -0
- package/dist/components/ActivityIndicator/index.d.ts +12 -0
- package/dist/components/ActivityIndicator/index.js +60 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/styles.d.ts +42 -0
- package/dist/components/ActivityIndicator/styles.js +22 -0
- package/dist/components/ActivityIndicator/styles.js.map +1 -0
- package/dist/components/Button.d.ts +15 -0
- package/dist/components/Button.js +48 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/CenterWrapper.d.ts +7 -0
- package/dist/components/CenterWrapper.js +28 -0
- package/dist/components/CenterWrapper.js.map +1 -0
- package/dist/components/Checkbox.d.ts +11 -0
- package/dist/components/Checkbox.js +46 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/ContentView.d.ts +10 -0
- package/dist/components/ContentView.js +52 -0
- package/dist/components/ContentView.js.map +1 -0
- package/dist/components/Drawer.d.ts +23 -0
- package/dist/components/Drawer.js +66 -0
- package/dist/components/Drawer.js.map +1 -0
- package/dist/components/FileInput.d.ts +8 -0
- package/dist/components/FileInput.js +69 -0
- package/dist/components/FileInput.js.map +1 -0
- package/dist/components/FlatList.d.ts +18 -0
- package/dist/components/FlatList.js +52 -0
- package/dist/components/FlatList.js.map +1 -0
- package/dist/components/HorizontalScroll.d.ts +3 -0
- package/dist/components/HorizontalScroll.js +42 -0
- package/dist/components/HorizontalScroll.js.map +1 -0
- package/dist/components/Icon.d.ts +12 -0
- package/dist/components/Icon.js +21 -0
- package/dist/components/Icon.js.map +1 -0
- package/dist/components/Link.d.ts +6 -0
- package/dist/components/Link.js +66 -0
- package/dist/components/Link.js.map +1 -0
- package/dist/components/Modal/index.d.ts +19 -0
- package/dist/components/Modal/index.js +111 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/styles.d.ts +44 -0
- package/dist/components/Modal/styles.js +33 -0
- package/dist/components/Modal/styles.js.map +1 -0
- package/dist/components/Overlay.d.ts +10 -0
- package/dist/components/Overlay.js +41 -0
- package/dist/components/Overlay.js.map +1 -0
- package/dist/components/PageRouter/Menu.d.ts +10 -0
- package/dist/components/PageRouter/Menu.js +36 -0
- package/dist/components/PageRouter/Menu.js.map +1 -0
- package/dist/components/PageRouter/MenuItem.d.ts +11 -0
- package/dist/components/PageRouter/MenuItem.js +42 -0
- package/dist/components/PageRouter/MenuItem.js.map +1 -0
- package/dist/components/PageRouter/Router.d.ts +8 -0
- package/dist/components/PageRouter/Router.js +27 -0
- package/dist/components/PageRouter/Router.js.map +1 -0
- package/dist/components/PageRouter/index.d.ts +15 -0
- package/dist/components/PageRouter/index.js +76 -0
- package/dist/components/PageRouter/index.js.map +1 -0
- package/dist/components/RadioInput/index.d.ts +62 -0
- package/dist/components/RadioInput/index.js +53 -0
- package/dist/components/RadioInput/index.js.map +1 -0
- package/dist/components/RadioInput/styles.d.ts +43 -0
- package/dist/components/RadioInput/styles.js +44 -0
- package/dist/components/RadioInput/styles.js.map +1 -0
- package/dist/components/Select.d.ts +17 -0
- package/dist/components/Select.js +44 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Slider.d.ts +5 -0
- package/dist/components/Slider.js +36 -0
- package/dist/components/Slider.js.map +1 -0
- package/dist/components/Text.d.ts +9 -0
- package/dist/components/Text.js +39 -0
- package/dist/components/Text.js.map +1 -0
- package/dist/components/TextInput.d.ts +122 -0
- package/dist/components/TextInput.js +125 -0
- package/dist/components/TextInput.js.map +1 -0
- package/dist/components/Tooltip-old.d.ts +11 -0
- package/dist/components/Tooltip-old.js +151 -0
- package/dist/components/Tooltip-old.js.map +1 -0
- package/dist/components/Tooltip.d.ts +12 -0
- package/dist/components/Tooltip.js +124 -0
- package/dist/components/Tooltip.js.map +1 -0
- package/dist/components/Touchable.d.ts +12 -0
- package/dist/components/Touchable.js +48 -0
- package/dist/components/Touchable.js.map +1 -0
- package/dist/components/View.d.ts +9 -0
- package/dist/components/View.js +47 -0
- package/dist/components/View.js.map +1 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/components/index.js +35 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/router/Menu.d.ts +10 -0
- package/dist/components/router/Menu.js +39 -0
- package/dist/components/router/Menu.js.map +1 -0
- package/dist/components/router/MenuItem.d.ts +11 -0
- package/dist/components/router/MenuItem.js +42 -0
- package/dist/components/router/MenuItem.js.map +1 -0
- package/dist/components/router/Router.d.ts +8 -0
- package/dist/components/router/Router.js +28 -0
- package/dist/components/router/Router.js.map +1 -0
- package/dist/components/router/index.d.ts +14 -0
- package/dist/components/router/index.js +69 -0
- package/dist/components/router/index.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/hooks.d.ts +8 -0
- package/dist/lib/hooks.js +49 -0
- package/dist/lib/hooks.js.map +1 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +16 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/utils/cookies.d.ts +6 -0
- package/dist/lib/utils/cookies.js +15 -0
- package/dist/lib/utils/cookies.js.map +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.js +23 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/pollyfils/scroll.d.ts +1 -0
- package/dist/lib/utils/pollyfils/scroll.js +58 -0
- package/dist/lib/utils/pollyfils/scroll.js.map +1 -0
- package/dist/lib/utils/stopPropagation.d.ts +1 -0
- package/dist/lib/utils/stopPropagation.js +21 -0
- package/dist/lib/utils/stopPropagation.js.map +1 -0
- package/dist/types/utility.d.ts +2 -0
- package/dist/types/utility.js +3 -0
- package/dist/types/utility.js.map +1 -0
- package/package.json +38 -0
- package/src/components/ActivityIndicator/index.tsx +55 -0
- package/src/components/ActivityIndicator/styles.ts +18 -0
- package/src/components/Button.tsx +67 -0
- package/src/components/CenterWrapper.tsx +24 -0
- package/src/components/Checkbox.tsx +46 -0
- package/src/components/ContentView.tsx +48 -0
- package/src/components/Drawer.tsx +114 -0
- package/src/components/FileInput.tsx +48 -0
- package/src/components/FlatList.tsx +77 -0
- package/src/components/HorizontalScroll.tsx +24 -0
- package/src/components/Icon.tsx +26 -0
- package/src/components/Link.tsx +51 -0
- package/src/components/Modal/index.tsx +150 -0
- package/src/components/Modal/styles.ts +49 -0
- package/src/components/Overlay.tsx +25 -0
- package/src/components/PageRouter/Menu.tsx +49 -0
- package/src/components/PageRouter/MenuItem.tsx +55 -0
- package/src/components/PageRouter/Router.tsx +23 -0
- package/src/components/PageRouter/index.tsx +81 -0
- package/src/components/RadioInput/index.tsx +72 -0
- package/src/components/RadioInput/styles.ts +57 -0
- package/src/components/Select.tsx +60 -0
- package/src/components/Slider.tsx +14 -0
- package/src/components/Text.tsx +27 -0
- package/src/components/TextInput.tsx +219 -0
- package/src/components/Tooltip.tsx +138 -0
- package/src/components/Touchable.tsx +47 -0
- package/src/components/View.tsx +54 -0
- package/src/components/index.ts +23 -0
- package/src/index.ts +4 -0
- package/src/lib/hooks.ts +42 -0
- package/src/lib/logger.ts +15 -0
- package/src/lib/utils/cookies.ts +19 -0
- package/src/lib/utils/index.ts +4 -0
- package/src/lib/utils/pollyfils/scroll.ts +59 -0
- package/src/lib/utils/stopPropagation.ts +17 -0
- package/src/types/utility.ts +4 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IconPlaceholder, useStyle } from '@codeleap/common'
|
|
2
|
+
|
|
3
|
+
export type IconProps = {
|
|
4
|
+
name:IconPlaceholder
|
|
5
|
+
style?: {
|
|
6
|
+
color: string
|
|
7
|
+
size?:string|number
|
|
8
|
+
width?:string|number
|
|
9
|
+
height?:string|number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Icon:React.FC<IconProps> = ({name, style}) => {
|
|
15
|
+
const {Theme} = useStyle()
|
|
16
|
+
if (!name) return null
|
|
17
|
+
const Component = Theme?.icons?.[name]
|
|
18
|
+
|
|
19
|
+
const {logger} = useStyle()
|
|
20
|
+
|
|
21
|
+
if (!Component) {
|
|
22
|
+
logger.warn('Icon', `No icon found in theme for name "${name}"`, 'Component')
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
return <Component style={style}/>
|
|
26
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
3
|
+
import { standardizeVariants, useStyle } from '@codeleap/common';
|
|
4
|
+
import { ElementType } from 'react';
|
|
5
|
+
import { TextProps } from './Text';
|
|
6
|
+
import { scrollToElem } from '../lib/utils/pollyfils/scroll';
|
|
7
|
+
import { stopPropagation } from '../lib/utils/stopPropagation';
|
|
8
|
+
import { Text } from './Text';
|
|
9
|
+
|
|
10
|
+
export type LinkProps<T extends ElementType> = TextProps<T> & {
|
|
11
|
+
openNewTab?:boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Link = <T extends ElementType = 'a'>(linkProps: LinkProps<T>) => {
|
|
15
|
+
const { variants, to, openNewTab, component = 'a', ...props } = linkProps
|
|
16
|
+
|
|
17
|
+
const isExternal = ['http', 'tel', 'mailto'].some(start => to.startsWith(start))
|
|
18
|
+
|
|
19
|
+
const Component = isExternal ? 'a' : component
|
|
20
|
+
const {logger} = useStyle()
|
|
21
|
+
function handleClick(event: React.MouseEvent){
|
|
22
|
+
logger.log('Link pressed', {to, text: linkProps.text }, 'Component')
|
|
23
|
+
if (to){
|
|
24
|
+
if (to.startsWith('#')){
|
|
25
|
+
event.preventDefault()
|
|
26
|
+
stopPropagation(event)
|
|
27
|
+
|
|
28
|
+
scrollToElem(to)
|
|
29
|
+
}
|
|
30
|
+
if (openNewTab){
|
|
31
|
+
window.open(to, '_blank')
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const passedVariants = standardizeVariants(variants || []) as TextProps<T>['variants']
|
|
37
|
+
|
|
38
|
+
const linkPropOverride = {
|
|
39
|
+
[isExternal ? 'href' : 'to']: to,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return <Text
|
|
43
|
+
component={Component}
|
|
44
|
+
{...props}
|
|
45
|
+
{...linkPropOverride}
|
|
46
|
+
text={props.text}
|
|
47
|
+
|
|
48
|
+
variants={[...passedVariants]}
|
|
49
|
+
onClick={handleClick}
|
|
50
|
+
/>
|
|
51
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { AnyFunction, ComponentVariants, IconPlaceholder, ModalComposition, ModalStyles, useComponentStyle } from '@codeleap/common';
|
|
3
|
+
import { jsx } from '@emotion/react';
|
|
4
|
+
import { ReactNode, useEffect, useLayoutEffect, useRef } from 'react';
|
|
5
|
+
import ReactDOM from 'react-dom';
|
|
6
|
+
import { v4 } from 'uuid';
|
|
7
|
+
import { StylesOf } from '../../types/utility';
|
|
8
|
+
import {Button} from '../Button'
|
|
9
|
+
import {View} from '../View'
|
|
10
|
+
import {Text} from '../Text'
|
|
11
|
+
import { Overlay } from '../Overlay';
|
|
12
|
+
|
|
13
|
+
export * from './styles'
|
|
14
|
+
|
|
15
|
+
export type ModalProps = {
|
|
16
|
+
|
|
17
|
+
open: boolean;
|
|
18
|
+
title?: React.ReactNode;
|
|
19
|
+
toggle: AnyFunction;
|
|
20
|
+
styles?: StylesOf<ModalComposition>
|
|
21
|
+
accessible?:boolean
|
|
22
|
+
showClose?: boolean
|
|
23
|
+
closable?: boolean
|
|
24
|
+
footer?: ReactNode
|
|
25
|
+
} & ComponentVariants<typeof ModalStyles>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
function focusModal(event: FocusEvent, id: string) {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
const modal = document.getElementById(id);
|
|
32
|
+
if (modal) {
|
|
33
|
+
modal.focus();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const ModalContent: React.FC<ModalProps & { id: string }> = (modalProps) => {
|
|
37
|
+
const {
|
|
38
|
+
children,
|
|
39
|
+
closable = true,
|
|
40
|
+
open,
|
|
41
|
+
title = '',
|
|
42
|
+
toggle,
|
|
43
|
+
id,
|
|
44
|
+
responsiveVariants,
|
|
45
|
+
variants,
|
|
46
|
+
styles,
|
|
47
|
+
showClose = true,
|
|
48
|
+
footer,
|
|
49
|
+
...props
|
|
50
|
+
} = modalProps
|
|
51
|
+
|
|
52
|
+
const variantStyles = useComponentStyle('Modal', {
|
|
53
|
+
responsiveVariants,
|
|
54
|
+
variants,
|
|
55
|
+
styles,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
function closeOnEscPress(e: React.KeyboardEvent<HTMLDivElement>) {
|
|
59
|
+
if (e.key === 'Escape') {
|
|
60
|
+
toggle();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
const modal = document.getElementById(id);
|
|
66
|
+
if (modal) {
|
|
67
|
+
modal.focus();
|
|
68
|
+
}
|
|
69
|
+
}, [id]);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<View aria-hidden={!open} css={variantStyles.wrapper} className={open ? 'visible' : ''}>
|
|
73
|
+
<Overlay visible={open} onClick={closable ? toggle : () => {}} css={variantStyles.overlay} />
|
|
74
|
+
<View
|
|
75
|
+
component='section'
|
|
76
|
+
css={{
|
|
77
|
+
...variantStyles.box,
|
|
78
|
+
// visibility: open ? 'visible' : 'hidden',
|
|
79
|
+
}}
|
|
80
|
+
className='content'
|
|
81
|
+
onKeyDown={closeOnEscPress}
|
|
82
|
+
tabIndex={0}
|
|
83
|
+
id={id}
|
|
84
|
+
aria-modal={true}
|
|
85
|
+
role='dialog'
|
|
86
|
+
aria-describedby={`${id}-title`}
|
|
87
|
+
aria-label='Close the modal by presing Escape key'
|
|
88
|
+
{...props}
|
|
89
|
+
>
|
|
90
|
+
{
|
|
91
|
+
(title || showClose) &&
|
|
92
|
+
|
|
93
|
+
<View component='header' className='modal-header header' id={`${id}-title`} css={variantStyles.header}>
|
|
94
|
+
|
|
95
|
+
{typeof title === 'string' ? <Text text={title}/> : title}
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
(showClose && closable) &&
|
|
99
|
+
<Button rightIcon={'close' as IconPlaceholder} variants={['icon']} onPress={toggle}/>
|
|
100
|
+
}
|
|
101
|
+
</View>
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
<View css={variantStyles.body}>
|
|
105
|
+
{children}
|
|
106
|
+
</View>
|
|
107
|
+
{
|
|
108
|
+
footer && <View component='footer' css={variantStyles.footer}>
|
|
109
|
+
{footer}
|
|
110
|
+
</View>
|
|
111
|
+
}
|
|
112
|
+
</View>
|
|
113
|
+
</View>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const Modal: React.FC<ModalProps> = ({accessible, ...props}) => {
|
|
118
|
+
const modalId = useRef(v4());
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (accessible){
|
|
122
|
+
|
|
123
|
+
const currentId = modalId.current;
|
|
124
|
+
const appRoot = document.body;
|
|
125
|
+
appRoot.addEventListener('focusin', (e) => focusModal(e, currentId));
|
|
126
|
+
return () => appRoot.removeEventListener('focusin', (e) => focusModal(e, currentId));
|
|
127
|
+
}
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (accessible){
|
|
132
|
+
|
|
133
|
+
const appRoot = document.body;
|
|
134
|
+
appRoot.setAttribute('aria-hidden', `${props.open}`);
|
|
135
|
+
appRoot.setAttribute('tabindex', `${-1}`);
|
|
136
|
+
}
|
|
137
|
+
}, [props.open]);
|
|
138
|
+
|
|
139
|
+
if (accessible){
|
|
140
|
+
if (props.open) {
|
|
141
|
+
document.body.style.overflow = 'hidden';
|
|
142
|
+
return ReactDOM.createPortal(<ModalContent {...props} id={modalId.current} />, document.body);
|
|
143
|
+
} else {
|
|
144
|
+
document.body.style.overflow = 'visible';
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return <ModalContent {...props} id={modalId.current} />
|
|
150
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, ModalComposition, ModalStyles } from '@codeleap/common'
|
|
2
|
+
|
|
3
|
+
const createModalStyle = createDefaultVariantFactory<ModalComposition>()
|
|
4
|
+
|
|
5
|
+
const transitionDuration = '0.3s'
|
|
6
|
+
|
|
7
|
+
export const WebModalStyles = {
|
|
8
|
+
...ModalStyles,
|
|
9
|
+
default: createModalStyle((theme) => {
|
|
10
|
+
const defaultStyles = ModalStyles.default(theme)
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
...defaultStyles,
|
|
14
|
+
wrapper: {
|
|
15
|
+
...defaultStyles.wrapper,
|
|
16
|
+
transition: `visibility 0.01s ease`,
|
|
17
|
+
transitionDelay: transitionDuration,
|
|
18
|
+
'& .content': {
|
|
19
|
+
transform: 'scale(0)',
|
|
20
|
+
transition: `transform ${transitionDuration} ease`,
|
|
21
|
+
},
|
|
22
|
+
'&.visible': {
|
|
23
|
+
visibility: 'visible',
|
|
24
|
+
transitionDelay: '0s',
|
|
25
|
+
},
|
|
26
|
+
'&.visible .content': {
|
|
27
|
+
visibility: 'visible',
|
|
28
|
+
transform: 'scale(1)',
|
|
29
|
+
},
|
|
30
|
+
'&.visible .overlay': {
|
|
31
|
+
opacity: 0.5,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
box: {
|
|
35
|
+
...defaultStyles.box,
|
|
36
|
+
width: '45vw',
|
|
37
|
+
|
|
38
|
+
},
|
|
39
|
+
overlay: {
|
|
40
|
+
...defaultStyles.overlay,
|
|
41
|
+
|
|
42
|
+
transition: `opacity ${transitionDuration} ease`,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}),
|
|
48
|
+
}
|
|
49
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentVariants, OverlayComposition, OverlayStyles, SmartOmit, StylesOf, useComponentStyle } from '@codeleap/common'
|
|
2
|
+
import { Touchable, TouchableProps } from './Touchable'
|
|
3
|
+
import { View, ViewProps } from './View'
|
|
4
|
+
|
|
5
|
+
export type OverlayProps = {
|
|
6
|
+
visible?:boolean
|
|
7
|
+
styles?: StylesOf<OverlayComposition>
|
|
8
|
+
onPress?: TouchableProps<'div'>['onClick']
|
|
9
|
+
} & ComponentVariants<typeof OverlayStyles> & Partial<SmartOmit<ViewProps<'div'>, 'variants' | 'responsiveVariants'>>
|
|
10
|
+
|
|
11
|
+
export const Overlay:React.FC<OverlayProps> = (overlayProps) => {
|
|
12
|
+
const {visible, responsiveVariants, variants, styles, ...props} = overlayProps
|
|
13
|
+
|
|
14
|
+
const variantStyles = useComponentStyle('Overlay', {
|
|
15
|
+
variants, responsiveVariants, styles,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const Component = props.onClick||props.onPress ? Touchable : View
|
|
19
|
+
|
|
20
|
+
return <Component css={{
|
|
21
|
+
...variantStyles.wrapper,
|
|
22
|
+
transition: 'opacity 0.2s ease',
|
|
23
|
+
...(visible ? variantStyles['wrapper:visible'] : {}),
|
|
24
|
+
}} {...props}/>
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { View } from '../View';
|
|
2
|
+
import { CenterWrapper } from '../CenterWrapper';
|
|
3
|
+
import {HorizontalScroll} from '../HorizontalScroll';
|
|
4
|
+
import { MenuItem, MenuItemProps } from './MenuItem';
|
|
5
|
+
import { useStyle, MenuComposition } from '@codeleap/common';
|
|
6
|
+
import { StylesOf } from '../../types/utility';
|
|
7
|
+
|
|
8
|
+
const TabsWrapper = ({children, styles}) => {
|
|
9
|
+
const {Theme} = useStyle()
|
|
10
|
+
const isMobile = Theme.hooks.down('small')
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const wrapperStyle = isMobile ? styles.topMenu : styles.sideMenu
|
|
15
|
+
|
|
16
|
+
if (isMobile){
|
|
17
|
+
return <View css={[wrapperStyle]}>
|
|
18
|
+
<CenterWrapper>
|
|
19
|
+
<View css={styles.mobileMenu}>
|
|
20
|
+
<HorizontalScroll css={styles.horizontalScroll}>
|
|
21
|
+
{children}
|
|
22
|
+
</HorizontalScroll>
|
|
23
|
+
</View>
|
|
24
|
+
</CenterWrapper>
|
|
25
|
+
</View>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return <View css={[wrapperStyle]}>
|
|
29
|
+
{children}
|
|
30
|
+
</View>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type RouterMenuProps = {
|
|
34
|
+
items: MenuItemProps['data'][]
|
|
35
|
+
styles?: StylesOf<MenuComposition>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export const Menu:React.FC<RouterMenuProps> = ({items, styles}) => {
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
return <TabsWrapper styles={styles}>
|
|
43
|
+
{
|
|
44
|
+
items.map(data => <MenuItem data={data} key={data.path} styles={styles}/>)
|
|
45
|
+
}
|
|
46
|
+
</TabsWrapper>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Text } from '../Text'
|
|
2
|
+
import { Icon } from '../Icon'
|
|
3
|
+
import { Link, LinkProps } from '../Link'
|
|
4
|
+
import { IconPlaceholder, MenuComposition, StylesOf, useStyle } from '@codeleap/common';
|
|
5
|
+
import { url } from '../../lib/utils';
|
|
6
|
+
import {Link as IntlLink} from 'gatsby-plugin-intl'
|
|
7
|
+
|
|
8
|
+
const RouterLink:React.FC<LinkProps<typeof IntlLink>> = (props) => <Link component={IntlLink} {...props}/>
|
|
9
|
+
|
|
10
|
+
export type MenuItemProps = {
|
|
11
|
+
data: {
|
|
12
|
+
icon: IconPlaceholder
|
|
13
|
+
title:string
|
|
14
|
+
path:string
|
|
15
|
+
}
|
|
16
|
+
styles: StylesOf<MenuComposition>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MenuItem:React.FC<MenuItemProps> = (props) => {
|
|
20
|
+
const { styles} = props
|
|
21
|
+
const { title, path, icon } = props.data;
|
|
22
|
+
|
|
23
|
+
const { pathname } = url();
|
|
24
|
+
|
|
25
|
+
const selected = pathname.includes(path);
|
|
26
|
+
const { Theme } = useStyle()
|
|
27
|
+
const isMobile = Theme.hooks.down('small')
|
|
28
|
+
|
|
29
|
+
if (isMobile){
|
|
30
|
+
return <RouterLink to={path} css={[styles['menuItem:mobile']]}>
|
|
31
|
+
<Text
|
|
32
|
+
variant={'p3'}
|
|
33
|
+
css={[
|
|
34
|
+
styles['menuItem:text:mobile'],
|
|
35
|
+
selected && styles['menuItem:text:selected'],
|
|
36
|
+
]}
|
|
37
|
+
msg={title}
|
|
38
|
+
/>
|
|
39
|
+
<Icon name={icon} />
|
|
40
|
+
</RouterLink>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (<RouterLink to={path}>
|
|
44
|
+
<Icon name={icon} />
|
|
45
|
+
<Text
|
|
46
|
+
variant={'p3'}
|
|
47
|
+
css={[
|
|
48
|
+
styles['menuItem:text'],
|
|
49
|
+
selected && styles['menuItem:text:selected'],
|
|
50
|
+
]}
|
|
51
|
+
msg={title}
|
|
52
|
+
/>
|
|
53
|
+
</RouterLink>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Router as ReachRouter } from '@reach/router';
|
|
3
|
+
|
|
4
|
+
type RouterProps = {
|
|
5
|
+
basePath:string
|
|
6
|
+
style?:any
|
|
7
|
+
defaultPath?:string
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const Router: React.FC<RouterProps> = (props) => {
|
|
11
|
+
const { children, style, basePath, defaultPath } = props;
|
|
12
|
+
const base = `/:language${basePath}`;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<React.Fragment>
|
|
17
|
+
|
|
18
|
+
<ReachRouter basepath={base}>
|
|
19
|
+
{children}
|
|
20
|
+
</ReachRouter>
|
|
21
|
+
</React.Fragment>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { View } from '../View'
|
|
2
|
+
import React, { useMemo } from 'react'
|
|
3
|
+
|
|
4
|
+
import { Menu } from './Menu'
|
|
5
|
+
import { Router } from './Router'
|
|
6
|
+
import { ComponentVariants, IconPlaceholder, PageRouterComposition, PageRouterStyles, useComponentStyle } from '@codeleap/common'
|
|
7
|
+
import { StylesOf } from '../../types/utility'
|
|
8
|
+
import { Helmet } from 'react-helmet'
|
|
9
|
+
import { url } from '../../lib/utils'
|
|
10
|
+
|
|
11
|
+
export type RouteProps = {
|
|
12
|
+
title?: string
|
|
13
|
+
path?: string
|
|
14
|
+
menuIcon?: IconPlaceholder
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export * from './Router'
|
|
19
|
+
|
|
20
|
+
type RouterPageProps = {
|
|
21
|
+
basePath:string
|
|
22
|
+
styles?: StylesOf<PageRouterComposition>
|
|
23
|
+
title?: string
|
|
24
|
+
} & ComponentVariants<typeof PageRouterStyles>
|
|
25
|
+
|
|
26
|
+
export const RouterPage:React.FC<RouterPageProps> = (props) => {
|
|
27
|
+
const {children, basePath, variants, title: pageGroupTitle, responsiveVariants, styles} = props
|
|
28
|
+
const pathName = url().pathname
|
|
29
|
+
|
|
30
|
+
const {menuItems, defaultPath} = useMemo(() => {
|
|
31
|
+
const items = []
|
|
32
|
+
|
|
33
|
+
let defaultPath = ''
|
|
34
|
+
|
|
35
|
+
React.Children.forEach(children, (c) => {
|
|
36
|
+
if (React.isValidElement(c) && c.props){
|
|
37
|
+
const {title, path, menuIcon} = c.props
|
|
38
|
+
if ([title, path, menuIcon].some((i) => !i)){
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (c.props.default) defaultPath = path
|
|
42
|
+
items.push({
|
|
43
|
+
...c.props,
|
|
44
|
+
title,
|
|
45
|
+
path: `${basePath}${path}`,
|
|
46
|
+
icon: menuIcon,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
menuItems: items,
|
|
53
|
+
defaultPath,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}, [children])
|
|
57
|
+
|
|
58
|
+
const variantStyles = useComponentStyle('PageRouter', {variants, responsiveVariants, styles})
|
|
59
|
+
|
|
60
|
+
const currentPage = menuItems.find(({path}) => pathName.includes(path))
|
|
61
|
+
return <>
|
|
62
|
+
<Helmet>
|
|
63
|
+
<title>
|
|
64
|
+
{(pageGroupTitle ? `${pageGroupTitle} | ` : '') + (currentPage ? currentPage?.title : '') }
|
|
65
|
+
</title>
|
|
66
|
+
</Helmet>
|
|
67
|
+
<Menu
|
|
68
|
+
items={menuItems}
|
|
69
|
+
styles={variantStyles}
|
|
70
|
+
/>
|
|
71
|
+
<View css={variantStyles.content}>
|
|
72
|
+
<Router
|
|
73
|
+
defaultPath={defaultPath}
|
|
74
|
+
basePath={basePath}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</Router>
|
|
78
|
+
</View>
|
|
79
|
+
</>
|
|
80
|
+
|
|
81
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ReactNode, useRef, ComponentPropsWithoutRef } from 'react'
|
|
2
|
+
import {v4} from 'uuid'
|
|
3
|
+
|
|
4
|
+
import {Text } from '../Text'
|
|
5
|
+
import { Touchable } from '../Touchable'
|
|
6
|
+
import { ComponentVariants, RadioInputComposition, RadioInputStyles, StylesOf, useComponentStyle } from '@codeleap/common'
|
|
7
|
+
import { View } from '../View'
|
|
8
|
+
export { WebRadioInputStyles } from './styles'
|
|
9
|
+
|
|
10
|
+
type RadioItem<T extends unknown = any> = {
|
|
11
|
+
value: T,
|
|
12
|
+
label: ReactNode
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const getRadioStyle = (props) => useComponentStyle('RadioInput', props)
|
|
16
|
+
|
|
17
|
+
export type RadioButtonProps = Omit<ComponentPropsWithoutRef<'input'>, 'style'> & {
|
|
18
|
+
item: RadioItem
|
|
19
|
+
select: () => void
|
|
20
|
+
style: ReturnType<typeof getRadioStyle>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type RadioGroupProps<T> = {
|
|
24
|
+
options: RadioItem<T>[]
|
|
25
|
+
value: T
|
|
26
|
+
onValueChange(value:T):void
|
|
27
|
+
label:ReactNode
|
|
28
|
+
styles?: StylesOf<RadioInputComposition>
|
|
29
|
+
} & ComponentVariants<typeof RadioInputStyles>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export const RadioButton:React.FC<RadioButtonProps> = ({item, select, style, checked, ...props}) => {
|
|
33
|
+
const styleByState = checked ? style['button:checked'] : style['button:unchecked']
|
|
34
|
+
return <Touchable onPress={select} css={style.itemWrapper} >
|
|
35
|
+
<View css={{
|
|
36
|
+
...style.button,
|
|
37
|
+
...styleByState,
|
|
38
|
+
'&:after': {
|
|
39
|
+
...style['button:mark'],
|
|
40
|
+
...styleByState?.['&:after'],
|
|
41
|
+
},
|
|
42
|
+
}}/>
|
|
43
|
+
{typeof item.label === 'string' ? <Text text={item.label} css={style.itemText}/> : item.label }
|
|
44
|
+
</Touchable>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export const RadioGroup = <T extends unknown>(radioGroupProps:RadioGroupProps<T>) => {
|
|
49
|
+
const {options, value, onValueChange, label, responsiveVariants, variants, styles} = radioGroupProps
|
|
50
|
+
const radioName = useRef(v4()).current
|
|
51
|
+
|
|
52
|
+
const radioStyle = getRadioStyle({
|
|
53
|
+
responsiveVariants,
|
|
54
|
+
variants,
|
|
55
|
+
styles,
|
|
56
|
+
})
|
|
57
|
+
return <View css={radioStyle.wrapper}>
|
|
58
|
+
{typeof label === 'string' ? <Text text={label}/> : label }
|
|
59
|
+
<View css={radioStyle.listWrapper}>
|
|
60
|
+
{
|
|
61
|
+
options?.map((item, idx) => <RadioButton
|
|
62
|
+
item={item}
|
|
63
|
+
key={idx}
|
|
64
|
+
style={radioStyle}
|
|
65
|
+
name={radioName}
|
|
66
|
+
checked={value === item.value}
|
|
67
|
+
select={() => onValueChange(item.value)}
|
|
68
|
+
/>)
|
|
69
|
+
}
|
|
70
|
+
</View>
|
|
71
|
+
</View>
|
|
72
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, RadioInputComposition, RadioInputStyles } from '@codeleap/common';
|
|
2
|
+
|
|
3
|
+
const createRadioStyle = createDefaultVariantFactory<RadioInputComposition>()
|
|
4
|
+
|
|
5
|
+
const defaultStyles = RadioInputStyles.default
|
|
6
|
+
|
|
7
|
+
export const WebRadioInputStyles = {
|
|
8
|
+
...RadioInputStyles,
|
|
9
|
+
default: createRadioStyle((theme) => {
|
|
10
|
+
const style = defaultStyles(theme)
|
|
11
|
+
return {
|
|
12
|
+
...style,
|
|
13
|
+
itemWrapper: {
|
|
14
|
+
...style.itemWrapper,
|
|
15
|
+
cursor: 'pointer',
|
|
16
|
+
},
|
|
17
|
+
button: {
|
|
18
|
+
height: '1em',
|
|
19
|
+
width: '1em',
|
|
20
|
+
borderRadius: theme.borderRadius.large,
|
|
21
|
+
border: theme.border.primary(1),
|
|
22
|
+
|
|
23
|
+
position: 'relative',
|
|
24
|
+
...theme.spacing.marginRight(1),
|
|
25
|
+
|
|
26
|
+
},
|
|
27
|
+
'button:mark': {
|
|
28
|
+
background: theme.colors.primary,
|
|
29
|
+
content: '""',
|
|
30
|
+
position: 'absolute',
|
|
31
|
+
left: '50%',
|
|
32
|
+
top: '50%',
|
|
33
|
+
|
|
34
|
+
transform: 'translate(-50%,-50%)',
|
|
35
|
+
borderRadius: theme.borderRadius.large,
|
|
36
|
+
height: '50%',
|
|
37
|
+
width: '50%',
|
|
38
|
+
visibility: 'hidden',
|
|
39
|
+
},
|
|
40
|
+
'button:checked': {
|
|
41
|
+
'&:after': {
|
|
42
|
+
visibility: 'visible',
|
|
43
|
+
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
square: createRadioStyle(() => ({
|
|
49
|
+
'button:mark': {
|
|
50
|
+
borderRadius: '1px',
|
|
51
|
+
},
|
|
52
|
+
button: {
|
|
53
|
+
borderRadius: '1px',
|
|
54
|
+
|
|
55
|
+
},
|
|
56
|
+
})),
|
|
57
|
+
}
|