graphen 1.10.9 → 1.10.10

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": "graphen",
3
- "version": "1.10.9",
3
+ "version": "1.10.10",
4
4
  "description": "Graphen is a small library, that keeps reusable blocks of UI and helps making application design consistent across multiple projects.",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -0,0 +1,49 @@
1
+ import React, { useState, useEffect } from "react";
2
+ import classNames from "classnames";
3
+
4
+ type Props = {
5
+ isSwitched?: boolean;
6
+ type?: "success" | "info" | "danger";
7
+ onChange?: (arg0: boolean) => void;
8
+ };
9
+
10
+ function Switch(props: Props) {
11
+ const { onChange, type, isSwitched } = props;
12
+ const [isChecked, setIsChecked] = useState(isSwitched);
13
+
14
+ useEffect(() => {
15
+ setIsChecked(isSwitched);
16
+ }, [isSwitched]);
17
+
18
+ const switchClasses = classNames("gc-switch", {
19
+ 'gc-switch--success': type === "success",
20
+ 'gc-switch--info': type === "info",
21
+ 'gc-switch--danger': type === "danger",
22
+ });
23
+
24
+ return (
25
+ // eslint-disable-next-line jsx-a11y/label-has-associated-control
26
+ <label className={switchClasses}>
27
+ <input
28
+ className="gc-switch__input"
29
+ type="checkbox"
30
+ onChange={(event) => {
31
+ const { checked } = event.target;
32
+ setIsChecked(checked);
33
+ onChange(checked);
34
+ }}
35
+ checked={isChecked}
36
+ />
37
+ <span className="gc-switch__slider" />
38
+ </label>
39
+ );
40
+ }
41
+
42
+ // @ts-ignore
43
+ Switch.defaultProps = {
44
+ isSwitched: false,
45
+ type: undefined,
46
+ onChange: () => {},
47
+ };
48
+
49
+ export default Switch;
package/src/example.tsx CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  Tooltip,
18
18
  Logo,
19
19
  Dropdown,
20
+ Switch,
20
21
  constants,
21
22
  } from "./index";
22
23
 
@@ -340,41 +341,10 @@ class ExampleApp extends React.PureComponent<Props, State> {
340
341
  <header className="gc-panel__title">Switches</header>
341
342
  <div className="gc-panel__content">
342
343
  <p>
343
- <label htmlFor="switch-1" className="gc-switch">
344
- <input
345
- id="switch-1"
346
- className="gc-switch__input"
347
- type="checkbox"
348
- />
349
- <span className="gc-switch__slider" />
350
- </label>{" "}
351
- <label
352
- htmlFor="switch-2"
353
- className="gc-switch gc-switch--success"
354
- >
355
- <input
356
- id="switch-2"
357
- className="gc-switch__input"
358
- type="checkbox"
359
- />
360
- <span className="gc-switch__slider" />
361
- </label>{" "}
362
- <label htmlFor="switch-3" className="gc-switch gc-switch--info">
363
- <input
364
- id="switch-3"
365
- className="gc-switch__input"
366
- type="checkbox"
367
- />
368
- <span className="gc-switch__slider" />
369
- </label>{" "}
370
- <label htmlFor="switch-4" className="gc-switch gc-switch--danger">
371
- <input
372
- id="switch-4"
373
- className="gc-switch__input"
374
- type="checkbox"
375
- />
376
- <span className="gc-switch__slider" />
377
- </label>
344
+ <Switch />{" "}
345
+ <Switch type="success" isSwitched />{" "}
346
+ <Switch type="info" isSwitched />{" "}
347
+ <Switch type="danger" isSwitched />
378
348
  </p>
379
349
  </div>
380
350
  </article>
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ import Panel from "src/components/Panel";
20
20
  import PanelContent from "src/components/PanelContent";
21
21
  import PanelFooter from "src/components/PanelFooter";
22
22
  import PanelTitle from "src/components/PanelTitle";
23
+ import Switch from "src/components/Switch";
23
24
  import * as constants from "src/variables/constants";
24
25
 
25
26
  export {
@@ -45,6 +46,7 @@ export {
45
46
  PanelContent,
46
47
  PanelFooter,
47
48
  PanelTitle,
49
+ Switch,
48
50
  constants
49
51
  };
50
52