@plurid/plurid-ui-components-react 0.0.0-8 → 0.0.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.
@@ -7,6 +7,7 @@ export interface SwitchProperties {
7
7
  round?: boolean;
8
8
  exclusive?: boolean;
9
9
  accent?: string;
10
+ Icon?: React.FC<any>;
10
11
  atChange: () => void;
11
12
  }
12
13
  declare const Switch: React.FC<SwitchProperties>;
@@ -1,2 +1,3 @@
1
1
  export declare const StyledSwitch: any;
2
2
  export declare const StyledSwitchSlider: any;
3
+ export declare const StyledSwitchIcon: any;
@@ -1622,17 +1622,26 @@ const StyledSwitch = styled.label`
1622
1622
  }
1623
1623
  `;
1624
1624
 
1625
- const StyledSwitchSlider = styled.span`
1626
- position: absolute;
1627
- cursor: pointer;
1628
- top: 0;
1629
- left: 0;
1630
- right: 0;
1631
- bottom: 0;
1632
- transition: .4s ease-in-out;
1633
- box-shadow: inset 0 2px 3px black;
1625
+ const levelBackgroundColor = props => {
1626
+ switch (props.level) {
1627
+ case 0:
1628
+ return props.theme.backgroundColorPrimary;
1634
1629
 
1635
- background-color: ${props => {
1630
+ case 1:
1631
+ return props.theme.backgroundColorSecondary;
1632
+
1633
+ case 2:
1634
+ return props.theme.backgroundColorTertiary;
1635
+
1636
+ case 3:
1637
+ return props.theme.backgroundColorQuaternary;
1638
+
1639
+ default:
1640
+ return props.theme.backgroundColorPrimary;
1641
+ }
1642
+ };
1643
+
1644
+ const backgroundColor = props => {
1636
1645
  if (props.accent) {
1637
1646
  return props.accent;
1638
1647
  }
@@ -1654,23 +1663,20 @@ const StyledSwitchSlider = styled.span`
1654
1663
  return props.theme.backgroundColorPrimaryAlpha;
1655
1664
  }
1656
1665
  }
1657
- switch (props.level) {
1658
- case 0:
1659
- return props.theme.backgroundColorPrimary;
1660
-
1661
- case 1:
1662
- return props.theme.backgroundColorSecondary;
1663
-
1664
- case 2:
1665
- return props.theme.backgroundColorTertiary;
1666
+ return levelBackgroundColor(props);
1667
+ };
1666
1668
 
1667
- case 3:
1668
- return props.theme.backgroundColorQuaternary;
1669
+ const StyledSwitchSlider = styled.span`
1670
+ position: absolute;
1671
+ cursor: pointer;
1672
+ top: 0;
1673
+ left: 0;
1674
+ right: 0;
1675
+ bottom: 0;
1676
+ transition: .4s ease-in-out;
1677
+ box-shadow: inset 0 2px 3px black;
1669
1678
 
1670
- default:
1671
- return props.theme.backgroundColorPrimary;
1672
- }
1673
- }};
1679
+ background-color: ${props => backgroundColor(props)};
1674
1680
  border-radius: ${props => {
1675
1681
  if (props.round) {
1676
1682
  return "34px";
@@ -1703,25 +1709,44 @@ const StyledSwitchSlider = styled.span`
1703
1709
  }
1704
1710
  `;
1705
1711
 
1712
+ const StyledSwitchIcon = styled.div`
1713
+ height: 100%;
1714
+ position: absolute;
1715
+ top: 0;
1716
+ display: flex;
1717
+ align-items: center;
1718
+ transition: .4s;
1719
+
1720
+ svg {
1721
+ fill: ${props => levelBackgroundColor(props)};
1722
+ }
1723
+ `;
1724
+
1706
1725
  const Switch = properties => {
1707
- const {checked: checked, theme: theme, level: level, round: round, exclusive: exclusive, accent: accent, atChange: atChange} = properties;
1726
+ const {checked: checked, theme: theme, level: level, round: round, exclusive: exclusive, accent: accent, Icon: Icon, atChange: atChange} = properties;
1708
1727
  const _theme = theme || plurid;
1709
1728
  const _level = level === undefined ? 0 : level;
1710
1729
  const _round = round === undefined ? true : round;
1730
+ const commonProperties = {
1731
+ theme: _theme,
1732
+ level: _level,
1733
+ exclusive: exclusive,
1734
+ checked: checked,
1735
+ accent: accent
1736
+ };
1711
1737
  return React.createElement(StyledSwitch, {
1712
1738
  theme: _theme
1713
1739
  }, React.createElement("input", {
1714
1740
  type: "checkbox",
1715
1741
  checked: checked,
1716
1742
  onChange: () => atChange()
1717
- }), React.createElement(StyledSwitchSlider, {
1718
- theme: _theme,
1719
- level: _level,
1720
- round: _round,
1721
- exclusive: exclusive,
1722
- checked: checked,
1723
- accent: accent
1724
- }));
1743
+ }), React.createElement(StyledSwitchSlider, Object.assign({
1744
+ round: _round
1745
+ }, commonProperties)), Icon && React.createElement(StyledSwitchIcon, Object.assign({}, commonProperties, {
1746
+ style: {
1747
+ left: checked ? "35px" : "9px"
1748
+ }
1749
+ }), React.createElement(Icon, null)));
1725
1750
  };
1726
1751
 
1727
1752
  const StyledInputSwitch = styled.div`