Socket
Socket
Sign inDemoInstall

@cicciosgamino/images-switch

Package Overview
Dependencies
6
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cicciosgamino/images-switch

Simple Lit switch, toggle between two background images (SVG)


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

[3.0.0] - 27-05-2021

Added

  • New CSS Custom Properties
  • New Examples

Changed

  • README.md

Readme

Source

GitHub issues npm version Published on webcomponents.org

💫 <images-switch>

Simple images-switch Lit component, you can switch between SVG image in background. Higly

examplesusageapiaccessibilitytodo

🕹️ Examples

Example Microsoft

--switch-width: 150px;
--switch-height: 60px;
--circle-margin: 15px;

--switch-border: 4px solid #000;
--switch-border-checked: 4px solid #00a2ed;

--switch-bk-color: #fff;
--switch-bk-ck-color: #00a2ed;
--switch-bk-disabled-color: #ccc;

--circle-bkcolor: #000;
--circle-ck-bkcolor: whitesmoke;

--text-font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
--text-font-size: 2rem;
--text-font-weight: 300;
<!-- Images switch -->
<images-switch truetext="On" falsetext="Off"></images-switch>

Example Camping

--switch-width: 160px;
--switch-height: 80px;

--circle-margin: 9px;

--circle-bkcolor: whitesmoke;
--circle-ck-bkcolor: whitesmoke;

--switch-bk-ck-url: url(/images/dark_o.svg);
--switch-bk-url: url(/images/light_o.svg);
--switch-bk-disabled-url: url(/images/disabled_o.svg);
<images-switch></images-switch>

Example Github

--switch-width: 160px;
--switch-height: 80px;
--switch-border: 4px solid #000;
--switch-border-checked: 4px solid #faf614;
--circle-url: url(/images/moon.svg);

--color-scale-purple-6: #6e40c9;
--color-scale-purple-9: #271052;

--circle-margin: -7px;
--bk-ck-color: var(--color-scale-purple-9);
--circle-bkcolor: #040d21;
--circle-ck-bkcolor: var(--color-scale-purple-6);
<images-switch></images-switch>

Example Check

--switch-width: 160px;
--switch-height: 80px;
--circle-margin: 9px;

--border: none;
--switch-bk-color: #ff5683;
--switch-bk-ck-color: #72e06f;
--switch-bk-disabled-color: #bbb;
--circle-bkcolor: whitesmoke;
--circle-ck-bkcolor: whitesmoke;

--switch-bk-ck-url: url(/images/check.svg);
--switch-bk-url: url(/images/cross.svg);

--switch-shadow: inset 0 0 10px rgba(0, 0, 0, 0.6);
--circle-shadow: 0 0 0px 2px rgba(100, 100, 100, 0.2);
--circle-shadow-focus-on: 0 0 5px 6px #FFDE03;
--circle-shadow-hover-on: 0 0 5px 6px #FFDE03; 

--text-font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
<images-switch></images-switch>

🚀 Usage

  1. Install package
npm install --save @cicciosgamino/images-switch
  1. Import
<!-- Import Js Module -->
<script type="module">
  // Importing this module registers <progress-ring> as an element that you
  // can use in this page.
  //
  // Note this import is a bare module specifier, so it must be converted
  // to a path using a server such as @web/dev-server.
  import '@cicciosgamino/images-switch'
</script>
  1. Place in your HTML
<images-switch truetext="On" falsetext="Off"></images-switch>

🐝 API

📒 Properties/Attributes

NameTypeDefaultDescription
valueString''Input value field
checkedBooleanfalseInput checked attribute
disabledBooleanfalseInput diabled attribute
trueTextString''Property to set the text of the switch when true
falseTextString''Property to set the text of the switch when false

Methods

None

Events

Event NameTargetDetailDescription
changeimages-switch{ checked: checked }Fired when the switch changes status

🧁 CSS Custom Properties

NameDefaultDescription
--switch-width80pxSwitch width
--switch-height40pxSwitch height
--switch-bordernoneSwitch border when unchecked
--switch-border-checkednoneSwitch border when checked
--switch-shadownoneSwitch shadow (out or inside switch border)
--switch-bk-colortransparentSwitch background-color when unchecked
--switch-bk-ck-colortransparentSwitch background-color when checked
--switch-bk-disabled-colortransparentSwitch background-color when disabled
--switch-bk-focus-colortransparentSwitch background-color when focus
--switch-bk-hover-colortransparentSwitch background-color when hover
--switch-bk-urlnoneSwitch background SVG url when unchecked
--switch-bk-ck-urlnoneSwitch background SVG url when checked
--switch-bk-disabled-urlnoneSwitch background SVG url when disabled
--circle-urlnoneCircle SVG url
--circle-ck-urlnoneCircle SVG url when checked (TODO)
--circle-disabled-urlnoneCircle SVG url when disabled (TODO)
--circle-margin3pxCircle margin
--circle-bkcolortransparentCircle background-color when unchecked
--circle-ck-bkcolortransparentCircle background-color when checked
--circle-shadownoneCircle shadow
--circle-shadow-focus-onnoneCircle shadow when focus
--circle-shadow-hover-onnoneCircle shadow when hover
--text-font-familysans-serifFont-family if text is used
--text-font-size2remFont-size if text is used
--text-font-weight300Font-weight if text is used
--text-absolute-top-1.5remAbsolute position top
--text-absolute-right-7remAbsolute position right

🤖 Write HTML and JavaScript

Import the component's JavaScript module, use the component in your HTML, and control it with JavaScript, just like you would with a built-in element such as <button>:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My Example App</title>

    <!-- Add support for Web Components to older browsers. -->
    <script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>

  </head>
  <body>
    <!-- Use Web Components in your HTML like regular built-in elements. -->
    <images-switch></images-switch>

    <!-- The Material Web Components use standard JavaScript modules. -->
    <script type="module">

      // Importing this module registers <progress-ring> as an element that you
      // can use in this page.
      //
      // Note this import is a bare module specifier, so it must be converted
      // to a path using a server such as @web/dev-server.
      import '@cicciosgamino/images-switch'

      // Standard DOM APIs work with Web Components just like they do for
      // built-in elements.
      const s = document.querySelector('images-switch')
    </script>
  </body>
</html>

🚀 Serve

Serve your HTML with any server or build process that supports bare module specifier resolution (see next section):

# use globally instelled
npm install -g @web/dev-server

# install the project dev-dependencies and npm run
npm install
npm run serve

Bare module specifiers

All @cicciosgamino Lit components JavaScript modules that use bare module specifiers. Bare module specifiers are not yet supported by browsers, so it is necessary to use a tool that transforms them to a path (for example from @cicciosgamino/images-switch to ./node_modules/@cicciosgamino/images-switch/images-switch.js).

Two great choices for tools that do this are:

Contributing

Got something interesting you'd like to share? Learn about contributing.

💪 Accessibility

Actually acessibility is handled with the role=switch and mirrororing the checked and disabled attributes from the native checkbox input element to the <images-switch> web component.

🔧 TODO

  • More Examples
  • Basic Unit testing
  • Documentation
  • npm publish

CSS encapsulation

The elements HTML structure is initialized in a Shadow DOM, so it is impossible to apply CSS to it. If you need to change the element's default style for any reason, you should open up a new issue (or a pull request!), describing your use case, and we'll work with you on solving the problem.

Browser support

Browsers without native custom element support require a polyfill. Legacy browsers require various other polyfills. See [examples/index.html][example] for details.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

🧑‍💻 Author

@cicciosgamino
@cicciosgamino

Support

Reach out to me at one of the following places:

Donate

Donate help and contibutions!

License

GNU General Public License v3.0

Made 🧑‍💻 by @cicciosgamino

Keywords

FAQs

Last updated on 27 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc