@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.
@@ -1640,17 +1640,26 @@ const StyledSwitch = styled__default["default"].label`
1640
1640
  }
1641
1641
  `;
1642
1642
 
1643
- const StyledSwitchSlider = styled__default["default"].span`
1644
- position: absolute;
1645
- cursor: pointer;
1646
- top: 0;
1647
- left: 0;
1648
- right: 0;
1649
- bottom: 0;
1650
- transition: .4s ease-in-out;
1651
- box-shadow: inset 0 2px 3px black;
1643
+ const levelBackgroundColor = props => {
1644
+ switch (props.level) {
1645
+ case 0:
1646
+ return props.theme.backgroundColorPrimary;
1652
1647
 
1653
- background-color: ${props => {
1648
+ case 1:
1649
+ return props.theme.backgroundColorSecondary;
1650
+
1651
+ case 2:
1652
+ return props.theme.backgroundColorTertiary;
1653
+
1654
+ case 3:
1655
+ return props.theme.backgroundColorQuaternary;
1656
+
1657
+ default:
1658
+ return props.theme.backgroundColorPrimary;
1659
+ }
1660
+ };
1661
+
1662
+ const backgroundColor = props => {
1654
1663
  if (props.accent) {
1655
1664
  return props.accent;
1656
1665
  }
@@ -1672,23 +1681,20 @@ const StyledSwitchSlider = styled__default["default"].span`
1672
1681
  return props.theme.backgroundColorPrimaryAlpha;
1673
1682
  }
1674
1683
  }
1675
- switch (props.level) {
1676
- case 0:
1677
- return props.theme.backgroundColorPrimary;
1678
-
1679
- case 1:
1680
- return props.theme.backgroundColorSecondary;
1681
-
1682
- case 2:
1683
- return props.theme.backgroundColorTertiary;
1684
+ return levelBackgroundColor(props);
1685
+ };
1684
1686
 
1685
- case 3:
1686
- return props.theme.backgroundColorQuaternary;
1687
+ const StyledSwitchSlider = styled__default["default"].span`
1688
+ position: absolute;
1689
+ cursor: pointer;
1690
+ top: 0;
1691
+ left: 0;
1692
+ right: 0;
1693
+ bottom: 0;
1694
+ transition: .4s ease-in-out;
1695
+ box-shadow: inset 0 2px 3px black;
1687
1696
 
1688
- default:
1689
- return props.theme.backgroundColorPrimary;
1690
- }
1691
- }};
1697
+ background-color: ${props => backgroundColor(props)};
1692
1698
  border-radius: ${props => {
1693
1699
  if (props.round) {
1694
1700
  return "34px";
@@ -1721,25 +1727,44 @@ const StyledSwitchSlider = styled__default["default"].span`
1721
1727
  }
1722
1728
  `;
1723
1729
 
1730
+ const StyledSwitchIcon = styled__default["default"].div`
1731
+ height: 100%;
1732
+ position: absolute;
1733
+ top: 0;
1734
+ display: flex;
1735
+ align-items: center;
1736
+ transition: .4s;
1737
+
1738
+ svg {
1739
+ fill: ${props => levelBackgroundColor(props)};
1740
+ }
1741
+ `;
1742
+
1724
1743
  const Switch = properties => {
1725
- const {checked: checked, theme: theme, level: level, round: round, exclusive: exclusive, accent: accent, atChange: atChange} = properties;
1744
+ const {checked: checked, theme: theme, level: level, round: round, exclusive: exclusive, accent: accent, Icon: Icon, atChange: atChange} = properties;
1726
1745
  const _theme = theme || themes.plurid;
1727
1746
  const _level = level === undefined ? 0 : level;
1728
1747
  const _round = round === undefined ? true : round;
1748
+ const commonProperties = {
1749
+ theme: _theme,
1750
+ level: _level,
1751
+ exclusive: exclusive,
1752
+ checked: checked,
1753
+ accent: accent
1754
+ };
1729
1755
  return React__default["default"].createElement(StyledSwitch, {
1730
1756
  theme: _theme
1731
1757
  }, React__default["default"].createElement("input", {
1732
1758
  type: "checkbox",
1733
1759
  checked: checked,
1734
1760
  onChange: () => atChange()
1735
- }), React__default["default"].createElement(StyledSwitchSlider, {
1736
- theme: _theme,
1737
- level: _level,
1738
- round: _round,
1739
- exclusive: exclusive,
1740
- checked: checked,
1741
- accent: accent
1742
- }));
1761
+ }), React__default["default"].createElement(StyledSwitchSlider, Object.assign({
1762
+ round: _round
1763
+ }, commonProperties)), Icon && React__default["default"].createElement(StyledSwitchIcon, Object.assign({}, commonProperties, {
1764
+ style: {
1765
+ left: checked ? "35px" : "9px"
1766
+ }
1767
+ }), React__default["default"].createElement(Icon, null)));
1743
1768
  };
1744
1769
 
1745
1770
  const StyledInputSwitch = styled__default["default"].div`