aboutsummaryrefslogtreecommitdiffstats
path: root/packages/forms/src/toggle/index.tsx
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-03-18 03:28:03 -0700
committerLibravatar GitHub <noreply@github.com>2019-03-18 03:28:03 -0700
commit6134c1b49f919dd2c578bc490829d68e4d210f4e (patch)
tree1ad6530fbb7f19e4e9c9a235c6b44e0dfdbc47d4 /packages/forms/src/toggle/index.tsx
parentAdd missing bracket in brew install help (#1205) (diff)
downloadferdium-app-6134c1b49f919dd2c578bc490829d68e4d210f4e.tar.gz
ferdium-app-6134c1b49f919dd2c578bc490829d68e4d210f4e.tar.zst
ferdium-app-6134c1b49f919dd2c578bc490829d68e4d210f4e.zip
Release/5.0.1 beta.1 (#1344)
* Add lerna * Add theme * Add forms * Add misty config to build theme & forms * reset packages version * Publish - @meetfranz/forms@1.0.0 - @meetfranz/theme@1.0.0 * Reset package version * restructure packages * try ci with lerna * Fix missing packages in build * move storybook to root + typescript TODO: fix modules * Add lerna instructions * Merge * wip * Make packages work in electron, node and web * Finalize packages & replace storybook with homegrown `uidev` * Bring package-lock back in sync * Publish - @meetfranz/forms@1.0.1 - @meetfranz/theme@1.0.1 * fix webpack issue * expose legacy styles * Add toggle element to @meetfranz/forms * start typings package * Update package.json * Add buttons * Update theme * add types * Add mdi icons to buttons * Publish - @meetfranz/forms@1.0.2 - @meetfranz/theme@1.0.2 - @meetfranz/typings@0.0.1 * Button, add missing success state * Update lerna packages * Try to disable automatic npm ci * Try to get a working bundle * Add href and type to button component * Update packages * update versions * cleanup * Update package versions [ci skip] * Update versions * Add withTheme context to button * Update & reuse electron-rebuild * feat(Windows): Add option to quit Franz from Taskbar icon * Add missing withTheme * Fix package versions * Update versions * Add pageview event * Simplify analytics calls * Pin gulp-sass-variables to 1.1.1 * Add onFocus event * Add modal overlay color * remove legacy theme files * remove code * Add dialog to share franz on social media * Fix service count * remove ping * replace ms time strings with ms module * remove unused packages * fix value setter * new payment flow * fix module reference * feat(Spell check): Add en-gb spell check languages (#1306) * move devmode info * fix(Windows): Fix losing window when "Keep Franz in background" is enabled * fix(Service): Fix service zoom (cmd/ctrl+ & cmd/ctrl-) * fixes appveyor build issue * feat(App): Update electron to 4.0.7 * ignore intellij idea project files * Automatic i18n update (i18n.meetfranz.com) * feat(App): Add security checks for external URLs * setup react-intl translations managing script * use same zooming logic for all os * feat(Linux): Add auto updater for Linux AppImage builds * Add ctrl+ for zoom in on Windows * move translation scripts into src/i18n folder * only manage en-US translations * manage translations before git pushes * Fix unused i18n strings * Bump version to 5.0.1-beta.1 * fix(Service) shortcuts for activating prev/next service fixes #1298 * fix(Service): Fix shortcut for (un)muting notifications & audio * add missing react-intl files * correctly update services submenu on language change * fix(Windows): Fix copy & paste in service context menus Closes #1316 * fix(Linux): Fix minimized window focusing (#1304) (@skoruppa) * trigger build * Check if window is minimized before restoring it * restore() should be executed only when window is minimized * fix(Notifications): Fix notifications & notification click when icon is blob * Fix/service webview unmounting (#1328) * detach service when underlying webview unmounts * disable no-param-reassign eslint rule * Add notification debug events * Update electron to 4.0.8 Update required in order to fix performance degradation due to memory leak issue https://github.com/electron/electron/pull/16772. * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * 5.0.1-beta.1
Diffstat (limited to 'packages/forms/src/toggle/index.tsx')
-rw-r--r--packages/forms/src/toggle/index.tsx117
1 files changed, 117 insertions, 0 deletions
diff --git a/packages/forms/src/toggle/index.tsx b/packages/forms/src/toggle/index.tsx
new file mode 100644
index 000000000..6487f1d07
--- /dev/null
+++ b/packages/forms/src/toggle/index.tsx
@@ -0,0 +1,117 @@
1import { Theme } from '@meetfranz/theme';
2import classnames from 'classnames';
3import CSS from 'csstype';
4import React, { Component, createRef } from 'react';
5import injectStyle from 'react-jss';
6
7import { IFormField, IWithStyle, Omit } from '../typings/generic';
8
9import { Error } from '../error';
10import { Label } from '../label';
11import { Wrapper } from '../wrapper';
12
13interface IProps extends React.InputHTMLAttributes<HTMLInputElement>, IFormField, IWithStyle {
14 className?: string;
15}
16
17const styles = (theme: Theme) => ({
18 toggle: {
19 background: theme.toggleBackground,
20 borderRadius: theme.borderRadius,
21 height: theme.toggleHeight,
22 position: 'relative' as CSS.PositionProperty,
23 width: theme.toggleWidth,
24 },
25 button: {
26 background: theme.toggleButton,
27 borderRadius: '100%',
28 boxShadow: '0 1px 4px rgba(0, 0, 0, .3)',
29 width: theme.toggleHeight - 2,
30 height: theme.toggleHeight - 2,
31 left: 1,
32 top: 1,
33 position: 'absolute' as CSS.PositionProperty,
34 transition: 'all .5s',
35 },
36 buttonActive: {
37 background: theme.toggleButtonActive,
38 left: (theme.toggleWidth - theme.toggleHeight) + 1,
39 },
40 input: {
41 visibility: 'hidden' as any,
42 },
43 disabled: {
44 opacity: theme.inputDisabledOpacity,
45 },
46 toggleLabel: {
47 display: 'flex',
48
49 '& > span': {
50 order: 1,
51 marginLeft: 15,
52 marginTop: 2,
53 },
54 },
55});
56
57class ToggleComponent extends Component<IProps> {
58 public static defaultProps = {
59 onChange: () => {},
60 showLabel: true,
61 disabled: false,
62 error: '',
63 };
64
65 render() {
66 const {
67 classes,
68 className,
69 disabled,
70 error,
71 id,
72 label,
73 showLabel,
74 checked,
75 value,
76 onChange,
77 } = this.props;
78
79 return (
80 <Wrapper
81 className={className}
82 identifier="franz-toggle"
83 >
84 <Label
85 title={label}
86 showLabel={showLabel}
87 htmlFor={id}
88 className={classes.toggleLabel}
89 >
90 <div className={classnames({
91 [`${classes.toggle}`]: true,
92 [`${classes.disabled}`]: disabled,
93 })}>
94 <div className={classnames({
95 [`${classes.button}`]: true,
96 [`${classes.buttonActive}`]: checked,
97 })} />
98 <input
99 className={classes.input}
100 id={id || name}
101 type="checkbox"
102 checked={checked}
103 value={value}
104 onChange={onChange}
105 disabled={disabled}
106 />
107 </div>
108 </Label>
109 {error && (
110 <Error message={error} />
111 )}
112 </Wrapper>
113 );
114 }
115}
116
117export const Toggle = injectStyle(styles)(ToggleComponent);