lupine.components 1.0.26 → 1.1.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,6 +1,6 @@
1
1
  {
2
2
  "name": "lupine.components",
3
- "version": "1.0.26",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "author": "uuware.com",
6
6
  "homepage": "https://github.com/uuware/lupine.js",
@@ -42,7 +42,7 @@ export class ActionSheet {
42
42
  handleClose();
43
43
  };
44
44
  const onClickContainer = (event: any) => {
45
- if (closeWhenClickOutside !== false && event.target.className === 'act-sheet-box') {
45
+ if (closeWhenClickOutside !== false && event.target.classList.contains('act-sheet-box')) {
46
46
  handleClose();
47
47
  }
48
48
  };
@@ -3,11 +3,18 @@ import { Spinner02, SpinnerSize } from './spinner';
3
3
 
4
4
  export type DragRefreshCloseProps = () => void;
5
5
 
6
+ export type DragRefreshHookProps = {
7
+ setEnable: (enable: boolean) => void;
8
+ updateOnDragRefresh: (onDragRefresh: (close: DragRefreshCloseProps) => Promise<void>) => void;
9
+ };
10
+
6
11
  export type DragRefreshProps = {
7
12
  container: string;
8
13
  onDragRefresh: (close: DragRefreshCloseProps) => Promise<void>;
14
+ hook?: DragRefreshHookProps;
9
15
  };
10
16
 
17
+ // globally there should be only one DragFresh
11
18
  export const DragFresh = (props: DragRefreshProps) => {
12
19
  const css: CssProps = {
13
20
  display: 'flex',
@@ -20,7 +27,7 @@ export const DragFresh = (props: DragRefreshProps) => {
20
27
  top: '0',
21
28
  left: '0',
22
29
  width: '100%',
23
- zIndex: 3,
30
+ zIndex: 'var(--layer-dragged-item)',
24
31
  display: 'none',
25
32
  justifyContent: 'center',
26
33
  transition: 'opacity 0.5s ease',
@@ -32,6 +39,15 @@ export const DragFresh = (props: DragRefreshProps) => {
32
39
  },
33
40
  };
34
41
 
42
+ let isEnabled = true;
43
+ if (props.hook) {
44
+ props.hook.setEnable = (enable: boolean) => {
45
+ isEnabled = enable;
46
+ };
47
+ props.hook.updateOnDragRefresh = (onDragRefresh: (close: DragRefreshCloseProps) => Promise<void>) => {
48
+ props.onDragRefresh = onDragRefresh;
49
+ };
50
+ }
35
51
  const closeSpin = () => {
36
52
  const spinnerDom = ref.$('.drag-spinner') as HTMLDivElement;
37
53
  if (!spinnerDom) return;
@@ -53,12 +69,14 @@ export const DragFresh = (props: DragRefreshProps) => {
53
69
  let needRefresh = false;
54
70
  const maxHeight = 150;
55
71
  container.addEventListener('touchstart', (e: any) => {
72
+ if (!isEnabled) return;
56
73
  touchstartY = e.touches[0].clientY;
57
74
  touchstartX = e.touches[0].clientX;
58
75
  direction = '';
59
76
  needRefresh = false;
60
77
  });
61
78
  container.addEventListener('touchmove', (e: any) => {
79
+ if (!isEnabled) return;
62
80
  const touchY = e.touches[0].clientY;
63
81
  const touchX = e.touches[0].clientX;
64
82
  const movedY = touchY - touchstartY;
@@ -89,6 +107,7 @@ export const DragFresh = (props: DragRefreshProps) => {
89
107
  }
90
108
  });
91
109
  container.addEventListener('touchend', (e) => {
110
+ if (!isEnabled) return;
92
111
  if (direction === 'Y') {
93
112
  if (needRefresh) {
94
113
  props.onDragRefresh(closeSpin);
@@ -49,7 +49,7 @@ export class FloatWindow {
49
49
  contentOverflowY = 'auto', // set to unset for having popup menu inside
50
50
  }: FloatWindowShowProps): Promise<FloatWindowCloseProps> {
51
51
  const onClickContainer = (event: any) => {
52
- if (closeWhenClickOutside !== false && event.target.className === 'fwin-box') {
52
+ if (closeWhenClickOutside !== false && event.target.classList.contains('fwin-box')) {
53
53
  handleClose();
54
54
  }
55
55
  };
@@ -49,8 +49,3 @@ export class HtmlVar implements HtmlVarResult {
49
49
  };
50
50
  }
51
51
  }
52
-
53
- // For backward compatibility
54
- export const createHtmlVar = (initial?: string | VNode<any>): HtmlVarResult => {
55
- return new HtmlVar(initial);
56
- };
@@ -30,6 +30,7 @@ export * from './spinner';
30
30
  export * from './svg';
31
31
  export * from './tabs';
32
32
  export * from './text-glow';
33
+ export * from './text-scale';
33
34
  export * from './text-wave';
34
35
  export * from './theme-selector';
35
36
  export * from './toggle-base';
@@ -283,7 +283,7 @@ export const MenuSidebar = ({
283
283
  };
284
284
 
285
285
  // if this component is used twice, then the Global styles is only set at the first time
286
- bindGlobalStyles('menu-sidebar-box', '.menu-sidebar-box', css);
286
+ bindGlobalStyles('menu-sidebar-box', css);
287
287
 
288
288
  // show the menu on both mobile and desktop
289
289
  const newCss: CssProps =
@@ -39,6 +39,7 @@ export const MobileHeaderTitleIcon = ({ title, onBack, left, right }: MobileHead
39
39
  padding: '6px 0',
40
40
  backgroundColor: 'var(--activatable-bg-color-normal)',
41
41
  boxShadow: 'var(--mobile-header-shadow)',
42
+ zIndex: 'var(--layer-inside)', // bring boxShadow to front
42
43
  '.mhti-title': {
43
44
  display: 'flex',
44
45
  fontSize: '1.3rem',
@@ -71,7 +71,7 @@ export class NotificationMessage {
71
71
  color: 'black',
72
72
  },
73
73
  };
74
- bindGlobalStyles('lj_notification', '.lj_notification', css);
74
+ bindGlobalStyles('lj_notification', css);
75
75
 
76
76
  let container = document.querySelector('.lj_notification');
77
77
  if (!container) {
@@ -70,7 +70,7 @@ export const PagingLink = ({
70
70
  },
71
71
  };
72
72
 
73
- bindGlobalStyles('paging-link-box', '.paging-link-box', css);
73
+ bindGlobalStyles('paging-link-box', css);
74
74
  pageIndex = pageIndex ?? (Number.parseInt(getRenderPageProps().query['pg_i'] || '') || 0);
75
75
  pageLimit = pageLimit || _DEFAULT_PAGE_LIMIT;
76
76
  let maxPages = Math.floor(itemsCount / pageLimit);
@@ -63,7 +63,7 @@ export class ResizableSplitter {
63
63
  backgroundColor: '#ccc',
64
64
  },
65
65
  };
66
- bindGlobalStyles('resizable-splitter', 'html', css);
66
+ bindGlobalStyles('resizable-splitter', css);
67
67
 
68
68
  window.addEventListener('mousemove', ResizableSplitter.onMousemove.bind(ResizableSplitter), false);
69
69
  document.documentElement.addEventListener('mouseup', ResizableSplitter.onMouseup.bind(ResizableSplitter), false);
@@ -1,4 +1,4 @@
1
- import { RefProps, VNode, mountInnerComponent } from 'lupine.web';
1
+ import { CssProps, RefProps, VNode, bindGlobalStyles, mountInnerComponent } from 'lupine.web';
2
2
  import { stopPropagation } from '../lib';
3
3
 
4
4
  export type TabsHookProps = {
@@ -27,28 +27,28 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
27
27
  const ref: RefProps = {};
28
28
  let newIndex = typeof defaultIndex === 'number' ? defaultIndex : 0;
29
29
  const clearIndex = () => {
30
- const header = ref.$(`.tabs[data-refid=${ref.id}] > div > .tab.active`);
30
+ const header = ref.$(`.&tabs > div > .tab.active`);
31
31
  header && header.classList.remove('active');
32
- const page = ref.$(`.pages[data-refid=${ref.id}] > .page.active`);
32
+ const page = ref.$(`.&pages > .page.active`);
33
33
  page && page.classList.remove('active');
34
34
  };
35
35
  const updateIndex = (index: number) => {
36
36
  clearIndex();
37
- const doms = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
37
+ const doms = ref.$all(`.&tabs > div > .tab`);
38
38
  if (index >= 0 && index < doms.length) {
39
39
  doms[index].classList.add('active');
40
- const pages = ref.$all(`.pages[data-refid=${ref.id}] > .page`);
40
+ const pages = ref.$all(`.&pages > .page`);
41
41
  pages[index].classList.add('active');
42
42
  refUpdate?.indexChanged && refUpdate?.indexChanged(index);
43
43
  }
44
44
  };
45
45
  const removePage = (index: number) => {
46
- const doms = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
46
+ const doms = ref.$all(`.&tabs > div > .tab`);
47
47
  if (index >= 0 && index < doms.length) {
48
48
  const newIndex = index === doms.length - 1 ? index - 1 : index;
49
49
  const isAct = doms[index].classList.contains('active');
50
50
  doms[index].parentNode.remove();
51
- const pages = ref.$all(`.pages[data-refid=${ref.id}] > .page`);
51
+ const pages = ref.$all(`.&pages > .page`);
52
52
  pages[index].remove();
53
53
 
54
54
  if (isAct) {
@@ -65,7 +65,7 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
65
65
  };
66
66
 
67
67
  const newPage = async (title: string, page: VNode<any>, index?: number) => {
68
- const allTabs = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
68
+ const allTabs = ref.$all(`.&tabs > div > .tab`);
69
69
  let newPageIndex = allTabs.length;
70
70
  if (typeof index === 'number' && index >= 0 && index < allTabs.length) {
71
71
  newPageIndex = index;
@@ -78,12 +78,12 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
78
78
  const newPage = document.createElement('div');
79
79
  newPage.className = 'page';
80
80
  if (newPageIndex === allTabs.length) {
81
- ref.$(`.tabs[data-refid=${ref.id}]`).appendChild(newTab);
82
- ref.$(`.pages[data-refid=${ref.id}]`).appendChild(newPage);
81
+ ref.$(`.&tabs`).appendChild(newTab);
82
+ ref.$(`.&pages`).appendChild(newPage);
83
83
  } else {
84
- ref.$(`.tabs[data-refid=${ref.id}]`).insertBefore(newTab, allTabs[newPageIndex]);
85
- const pages = ref.$all(`.pages[data-refid=${ref.id}] > .page`);
86
- ref.$(`.pages[data-refid=${ref.id}]`).insertBefore(newPage, pages[newPageIndex]);
84
+ ref.$(`.&tabs`).insertBefore(newTab, allTabs[newPageIndex]);
85
+ const pages = ref.$all(`.&pages > .page`);
86
+ ref.$(`.&pages`).insertBefore(newPage, pages[newPageIndex]);
87
87
  }
88
88
 
89
89
  await mountInnerComponent(newTab, newTab2);
@@ -108,7 +108,7 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
108
108
  updateIndex(index);
109
109
  };
110
110
  const flashTitle = (index: number) => {
111
- const doms = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
111
+ const doms = ref.$all(`.&tabs > div > .tab`);
112
112
  if (index >= 0 && index < doms.length) {
113
113
  doms[index].classList.add('flash');
114
114
  setTimeout(() => {
@@ -118,7 +118,7 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
118
118
  };
119
119
  if (refUpdate) {
120
120
  refUpdate.updateTitle = (index: number, title: string) => {
121
- const doms = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
121
+ const doms = ref.$all(`.&tabs > div > .tab`);
122
122
  if (index >= 0 && index < doms.length) {
123
123
  doms[index].innerHTML = title;
124
124
  }
@@ -127,15 +127,15 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
127
127
  refUpdate.removePage = removePage;
128
128
  refUpdate.newPage = newPage;
129
129
  refUpdate.getIndex = () => {
130
- const header = ref.$(`.tabs[data-refid=${ref.id}] > div > .tab.active`);
130
+ const header = ref.$(`.&tabs > div > .tab.active`);
131
131
  return header ? Array.prototype.indexOf.call(header.parentNode.parentNode.children, header.parentNode) : -1;
132
132
  };
133
133
  refUpdate.getCount = () => {
134
- const doms = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
134
+ const doms = ref.$all(`.&tabs > div > .tab`);
135
135
  return doms.length;
136
136
  };
137
137
  refUpdate.findAndActivate = (title: string) => {
138
- const doms = ref.$all(`.tabs[data-refid=${ref.id}] > div > .tab`);
138
+ const doms = ref.$all(`.&tabs > div > .tab`);
139
139
  for (let i = 0; i < doms.length; i++) {
140
140
  if (doms[i].innerText === title) {
141
141
  updateIndex(i);
@@ -148,7 +148,7 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
148
148
  }
149
149
 
150
150
  // pay attention to nest tabs
151
- const newCss: any = {
151
+ const css: CssProps = {
152
152
  display: 'flex',
153
153
  'flex-direction': 'column',
154
154
  width: '100%',
@@ -232,16 +232,27 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
232
232
  },
233
233
  },
234
234
  };
235
+ // we want to put all common styles in the header
236
+ bindGlobalStyles('s-tabs-box', css);
235
237
 
238
+ // but we also want to create unique id for the current tab
239
+ const cssTab: CssProps = {
240
+ '&tabs': {
241
+ display: 'flex',
242
+ },
243
+ '&pages': {
244
+ display: 'flex',
245
+ },
246
+ };
236
247
  return (
237
- <div ref={ref} css={newCss} class={'tabs-box' + (topClassName ? ' ' + topClassName : '')}>
238
- <div class='tabs' data-refid={ref}>
248
+ <div ref={ref} css={cssTab} class={'s-tabs-box' + (topClassName ? ' ' + topClassName : '')}>
249
+ <div class='&tabs tabs'>
239
250
  {pages.map((i, index) => {
240
251
  const className = index === newIndex ? ' active' : '';
241
252
  return <div>{createTabHeader(i.title, className)}</div>;
242
253
  })}
243
254
  </div>
244
- <div class='pages' data-refid={ref}>
255
+ <div class='&pages pages'>
245
256
  {pages.map((i, index) => {
246
257
  const className = index === newIndex ? ' active' : '';
247
258
  return <div class={'page' + className}>{i.page}</div>;
@@ -1,4 +1,4 @@
1
- import { CssProps } from 'lupine.web';
1
+ import { bindGlobalStyles, CssProps } from 'lupine.web';
2
2
 
3
3
  export type TextGlowProps = {
4
4
  text: string;
@@ -28,8 +28,9 @@ export const TextGlow = (props: TextGlowProps) => {
28
28
  },
29
29
  },
30
30
  };
31
+ bindGlobalStyles('text-glow-top', css);
31
32
  return (
32
- <div css={css} class='text-glow-top'>
33
+ <div class='text-glow-top'>
33
34
  <div class='text-glow'>{props.text}</div>
34
35
  </div>
35
36
  );
@@ -0,0 +1,42 @@
1
+ import { bindGlobalStyles, CssProps } from 'lupine.web';
2
+
3
+ export type TextScaleProps = {
4
+ text: string;
5
+ color?: string;
6
+ backgroundColor?: string;
7
+ padding?: string;
8
+ fontSize?: string;
9
+ fontWeight?: string;
10
+ };
11
+ export const TextScale = (props: TextScaleProps) => {
12
+ const css: CssProps = {
13
+ width: `100%`,
14
+ height: `100%`,
15
+ display: 'flex',
16
+ justifyContent: 'center',
17
+ alignItems: 'center',
18
+ color: props.color || '#22b8ff',
19
+ fontSize: props.fontSize || '30px',
20
+ fontWeight: props.fontWeight || '500',
21
+ '.text-scale': {
22
+ animation: 'text-scale 1.5s infinite alternate',
23
+ backgroundColor: props.backgroundColor || '#a1ffe8',
24
+ padding: props.padding || '10px',
25
+ borderRadius: '5px',
26
+ },
27
+ '@keyframes text-scale': {
28
+ '0%, 100%': {
29
+ transform: 'scale(1)',
30
+ },
31
+ '40%': {
32
+ transform: 'scale(0.7)',
33
+ },
34
+ },
35
+ };
36
+ bindGlobalStyles('text-scale-top', css);
37
+ return (
38
+ <div class='text-scale-top'>
39
+ <div class='text-scale'>{props.text}</div>
40
+ </div>
41
+ );
42
+ };
@@ -1,4 +1,4 @@
1
- import { CssProps } from "lupine.web";
1
+ import { bindGlobalStyles, CssProps } from "lupine.web";
2
2
 
3
3
  export type TextLoadingProps = {
4
4
  text: string;
@@ -21,12 +21,12 @@ export const TextWave = (props: TextLoadingProps) => {
21
21
  fontSize: props.fontSize || '20px',
22
22
  fontWeight: props.fontWeight,
23
23
  textShadow: '1px -1px #ffffff, -2px 2px #999, -6px 7px 3px #131f5be6',
24
- '.text-loading.wave-animetion span': {
24
+ '.text-wave.wave-animetion span': {
25
25
  display: 'inline-block',
26
26
  padding: '0 4px',
27
27
  animation: 'wave-text 1s ease-in-out infinite',
28
28
  },
29
- '.text-loading.wave-animetion': {
29
+ '.text-wave.wave-animetion': {
30
30
  marginTop: '0.6em',
31
31
  ...cssMap,
32
32
  },
@@ -42,9 +42,10 @@ export const TextWave = (props: TextLoadingProps) => {
42
42
  },
43
43
  },
44
44
  };
45
+ bindGlobalStyles('text-wave-top', css);
45
46
  return (
46
- <div css={css} class='text-loading-top'>
47
- <div class='text-loading wave-animetion'>
47
+ <div class='text-wave-top'>
48
+ <div class='text-wave wave-animetion'>
48
49
  {props.text.split('').map((char, index) => (
49
50
  <span class={`span${index}`}>{char}</span>
50
51
  ))}
@@ -1,20 +1,17 @@
1
- import { CssProps, bindGlobalStyles, getCurrentTheme, updateTheme } from 'lupine.web';
1
+ import { CssProps, getCurrentTheme, updateTheme } from 'lupine.web';
2
2
  import { PopupMenu } from './popup-menu';
3
3
 
4
4
  export type ThemeSelectorProps = {
5
5
  className?: string;
6
- css?: CssProps;
7
6
  };
8
7
 
9
- export const ThemeSelector = ({ className, css }: ThemeSelectorProps) => {
10
- const newCss: CssProps = {
8
+ export const ThemeSelector = ({ className }: ThemeSelectorProps) => {
9
+ const css: CssProps = {
11
10
  display: 'flex',
12
11
  flexDirection: 'column',
13
12
  alignSelf: 'end',
14
- ...css,
15
13
  };
16
14
 
17
- bindGlobalStyles('theme-switch', '.theme-switch', newCss);
18
15
  const handleSelected = (themeName: string) => {
19
16
  updateTheme(themeName);
20
17
  };
@@ -24,7 +21,7 @@ export const ThemeSelector = ({ className, css }: ThemeSelectorProps) => {
24
21
  list.push(themeName);
25
22
  }
26
23
  return (
27
- <div css={newCss} class={['theme-switch', className].join(' ')} title='Select theme'>
24
+ <div css={css} class={['theme-switch', className].join(' ')} title='Select theme'>
28
25
  <PopupMenu list={list} defaultValue={currentTheme.themeName} handleSelected={handleSelected}></PopupMenu>
29
26
  </div>
30
27
  );
@@ -1,22 +1,22 @@
1
- import { CssProps, RefProps, VNode } from 'lupine.web';
1
+ import { bindGlobalStyles, CssProps, RefProps, VNode } from 'lupine.web';
2
2
 
3
- export const PlayButtonSize = {
3
+ export const TogglePlayButtonSize = {
4
4
  Small: { w: 50, h: 50 },
5
5
  Medium: { w: 70, h: 70 },
6
6
  Large: { w: 90, h: 90 },
7
7
  };
8
- export type PlayButtonSizeProps = {
8
+ export type TogglePlayButtonSizeProps = {
9
9
  w: number;
10
10
  h: number;
11
11
  };
12
- export type PlayButtonProps = {
13
- size: PlayButtonSizeProps;
12
+ export type TogglePlayButtonProps = {
13
+ size: TogglePlayButtonSizeProps;
14
14
  disabled?: boolean;
15
15
  checked?: boolean;
16
16
  onClick?: (checked: boolean) => void;
17
17
  hook?: ToggleBaseHookProps;
18
18
  };
19
- export const PlayButton = (props: PlayButtonProps) => {
19
+ export const TogglePlayButton = (props: TogglePlayButtonProps) => {
20
20
  const css: CssProps = {
21
21
  width: `100%`,
22
22
  height: `100%`,
@@ -45,12 +45,12 @@ export const PlayButton = (props: PlayButtonProps) => {
45
45
  backgroundColor: '#5d578b',
46
46
  },
47
47
  };
48
+ bindGlobalStyles('toggle-play-button-component', css);
48
49
  return (
49
50
  <ToggleBase {...props}>
50
51
  <ToggleWaveFrame>
51
52
  <div
52
- css={css}
53
- class={`toggle-button-component toggle-placeholder ${props.checked ? 'toggle-on' : 'toggle-off'}${
53
+ class={`toggle-play-button-component toggle-placeholder ${props.checked ? 'toggle-on' : 'toggle-off'}${
54
54
  props.disabled ? ' disabled' : ''
55
55
  }`}
56
56
  >
@@ -62,7 +62,7 @@ export const PlayButton = (props: PlayButtonProps) => {
62
62
  };
63
63
 
64
64
  export type ToggleButtonProps = {
65
- size: ToggleBaseSizeProps;
65
+ // size: ToggleBaseSizeProps;
66
66
  onText: string;
67
67
  offText: string;
68
68
  disabled?: boolean;
@@ -85,7 +85,7 @@ export const ToggleButton = (props: ToggleButtonProps) => {
85
85
  },
86
86
  };
87
87
  return (
88
- <ToggleBase {...props}>
88
+ <ToggleBase {...props} size={{ w: 'auto', h: 'auto' }}>
89
89
  <div
90
90
  css={css}
91
91
  class={`toggle-button-component toggle-placeholder ${props.checked ? 'toggle-on' : 'toggle-off'}${
@@ -120,12 +120,11 @@ export const ToggleWaveFrame = (props: ToggleWaveFrameProps) => {
120
120
  position: 'absolute',
121
121
  width: `100%`,
122
122
  height: `100%`,
123
- top: '-0',
123
+ top: '0',
124
124
  left: '0',
125
125
  borderRadius: '50%',
126
126
  backgroundColor: '#eb205580',
127
127
  opacity: 0,
128
- zIndex: -1,
129
128
  animation: 'pulse-border 3s ease-in-out infinite',
130
129
  },
131
130
  '.toggle-waves-1': {
@@ -143,16 +142,20 @@ export const ToggleWaveFrame = (props: ToggleWaveFrameProps) => {
143
142
  'animation-delay': '2s',
144
143
  },
145
144
  '.toggle-waves-box': {
145
+ position: 'absolute',
146
146
  width: `100%`,
147
147
  height: `100%`,
148
+ top: '0',
149
+ left: '0',
148
150
  padding: `18%`,
149
151
  },
150
152
  '&.disabled .toggle-waves': {
151
153
  backgroundColor: '#5d578b',
152
154
  },
153
155
  };
156
+ bindGlobalStyles('toggle-waves-box', css);
154
157
  return (
155
- <div css={css} class='toggle-waves-box toggle-placeholder'>
158
+ <div class='toggle-waves-box toggle-placeholder'>
156
159
  <div class='toggle-waves toggle-waves-1'></div>
157
160
  <div class='toggle-waves toggle-waves-2'></div>
158
161
  <div class='toggle-waves toggle-waves-3'></div>
@@ -230,8 +233,6 @@ export const ToggleBase = (props: ToggleBaseProps) => {
230
233
  }
231
234
 
232
235
  const css: CssProps = {
233
- width: `${typeof props.size.w === 'number' ? props.size.w + 'px' : props.size.w}`,
234
- height: `${typeof props.size.h === 'number' ? props.size.h + 'px' : props.size.h}`,
235
236
  '.toggle-base-box, .toggle-base-container': {
236
237
  position: 'relative',
237
238
  width: `100%`,
@@ -243,8 +244,16 @@ export const ToggleBase = (props: ToggleBaseProps) => {
243
244
  pointerEvents: 'none',
244
245
  },
245
246
  };
247
+ bindGlobalStyles('toggle-base-component', css);
246
248
  return (
247
- <div ref={ref} css={css} class='toggle-base-component'>
249
+ <div
250
+ ref={ref}
251
+ css={{
252
+ width: `${typeof props.size.w === 'number' ? props.size.w + 'px' : props.size.w}`,
253
+ height: `${typeof props.size.h === 'number' ? props.size.h + 'px' : props.size.h}`,
254
+ }}
255
+ class='toggle-base-component'
256
+ >
248
257
  <label class='toggle-base-box'>
249
258
  <div class='toggle-base-container'>{props.children}</div>
250
259
  <input
@@ -25,7 +25,7 @@ export const ToggleSwitch = (props: ToggleSwitchProps) => {
25
25
  : props.size === ToggleSwitchSize.Large
26
26
  ? 42
27
27
  : 34;
28
- const cssSize =
28
+ const classSize =
29
29
  props.size === ToggleSwitchSize.SmallSmall
30
30
  ? 'smallsmall'
31
31
  : props.size === ToggleSwitchSize.Small
@@ -93,10 +93,6 @@ export const ToggleSwitch = (props: ToggleSwitchProps) => {
93
93
  bottom: '2px',
94
94
  },
95
95
 
96
- '& .ts-on-text, & .ts-off-text': {
97
- display: 'none',
98
- width: props.textWidth,
99
- },
100
96
  '&.toggle-on .ts-on-text': {
101
97
  display: 'block',
102
98
  },
@@ -136,14 +132,22 @@ export const ToggleSwitch = (props: ToggleSwitchProps) => {
136
132
  },
137
133
  };
138
134
 
139
- bindGlobalStyles('toggle-switch-theme', '', cssTheme);
135
+ bindGlobalStyles('toggle-switch-theme', cssTheme, false, true);
136
+ bindGlobalStyles('toggle-switch-component', css);
137
+
138
+ const cssSize: CssProps = {
139
+ '& .ts-on-text, & .ts-off-text': {
140
+ display: 'none',
141
+ width: props.textWidth,
142
+ },
143
+ };
140
144
  return (
141
145
  <ToggleBase {...props} size={{ w: 'auto', h: sizeH }}>
142
146
  <div
143
- css={css}
147
+ css={cssSize}
144
148
  class={`toggle-switch-component toggle-placeholder ${props.checked ? 'toggle-on' : 'toggle-off'}${
145
149
  props.disabled ? ' disabled' : ''
146
- } ${cssSize}`}
150
+ } ${classSize}`}
147
151
  >
148
152
  <span class='ts-slider'>
149
153
  <span class='ts-on-text'>{props.text?.on}</span>
@@ -0,0 +1,23 @@
1
+ export class Base62 {
2
+ private static ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
3
+ private static BASE = 62;
4
+ static toString(num: number) {
5
+ if (num === 0) return Base62.ALPHABET[0];
6
+
7
+ let result = '';
8
+ while (num > 0) {
9
+ const rem = num % Base62.BASE;
10
+ result = Base62.ALPHABET[rem] + result;
11
+ num = Math.floor(num / Base62.BASE);
12
+ }
13
+ return result;
14
+ }
15
+
16
+ static fromString(str: string) {
17
+ let result = 0;
18
+ for (let i = 0; i < str.length; i++) {
19
+ result = result * Base62.BASE + Base62.ALPHABET.indexOf(str[i]);
20
+ }
21
+ return result;
22
+ }
23
+ }
package/src/lib/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './base62';
1
2
  export * from './blob-utils';
2
3
  export * from './calculate-text-width';
3
4
  export * from './date-utils';