\n',customElements.define("sm-carousel",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCarousel.content.cloneNode(!0)),this.isAutoPlaying=!1,this.autoPlayInterval=5e3,this.autoPlayTimeout,this.initialTimeout,this.activeSlideNum=0,this.carouselItems,this.indicators,this.showIndicator=!1,this.carousel=this.shadowRoot.querySelector(".carousel"),this.carouselContainer=this.shadowRoot.querySelector(".carousel-container"),this.carouselSlot=this.shadowRoot.querySelector("slot"),this.navButtonRight=this.shadowRoot.querySelector(".carousel__button--right"),this.navButtonLeft=this.shadowRoot.querySelector(".carousel__button--left"),this.indicatorsContainer=this.shadowRoot.querySelector(".indicators"),this.scrollLeft=this.scrollLeft.bind(this),this.scrollRight=this.scrollRight.bind(this),this.handleIndicatorClick=this.handleIndicatorClick.bind(this),this.showSlide=this.showSlide.bind(this),this.nextSlide=this.nextSlide.bind(this),this.autoPlay=this.autoPlay.bind(this),this.startAutoPlay=this.startAutoPlay.bind(this),this.stopAutoPlay=this.stopAutoPlay.bind(this)}static get observedAttributes(){return["indicator","autoplay","interval"]}scrollLeft(){this.carousel.scrollBy({left:-this.scrollDistance,behavior:"smooth"})}scrollRight(){this.carousel.scrollBy({left:this.scrollDistance,behavior:"smooth"})}showSlide(t){this.carousel.scrollTo({left:this.carouselItems[t].getBoundingClientRect().left-this.carousel.getBoundingClientRect().left+this.carousel.scrollLeft,behavior:"smooth"})}nextSlide(){if(!this.carouselItems)return;let t=this.activeSlideNum+1{this.autoPlay()},this.autoPlayInterval))}startAutoPlay(){this.setAttribute("autoplay","")}stopAutoPlay(){this.removeAttribute("autoplay")}createIndicator(t){let n=document.createElement("div");return n.classList.add("dot"),n.dataset.rank=t,n}handleIndicatorClick(t){if(t.target.closest(".dot")){const n=parseInt(t.target.closest(".dot").dataset.rank);this.activeSlideNum!==n&&this.showSlide(n)}}handleKeyDown(t){"ArrowLeft"===t.code?this.scrollRight():"ArrowRight"===t.code&&this.scrollRight()}connectedCallback(){let t=document.createDocumentFragment();this.carouselSlot.addEventListener("slotchange",n=>{this.carouselItems=this.carouselSlot.assignedElements(),this.carouselItems.forEach(t=>e.observe(t)),this.carouselItems.length>0?(i.observe(this.carouselItems[0]),o.observe(this.carouselItems[this.carouselItems.length-1])):(navButtonLeft.classList.add("hide"),navButtonRight.classList.add("hide"),i.disconnect(),o.disconnect()),this.showIndicator&&(this.indicatorsContainer.innerHTML="",this.carouselItems.forEach((n,e)=>{t.append(this.createIndicator(e)),n.dataset.rank=e}),this.indicatorsContainer.append(t),this.indicators=this.indicatorsContainer.children)});const n={threshold:.9,root:this},e=new IntersectionObserver(t=>{t.forEach(t=>{if(this.showIndicator){const n=parseInt(t.target.dataset.rank);t.isIntersecting?(this.indicators[n].classList.add("active"),this.activeSlideNum=n):this.indicators[n].classList.remove("active")}})},n),i=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting?this.navButtonLeft.classList.add("hide"):this.navButtonLeft.classList.remove("hide")})},n),o=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting?this.navButtonRight.classList.add("hide"):this.navButtonRight.classList.remove("hide")})},n),s=new ResizeObserver(t=>{t.forEach(t=>{if(t.contentBoxSize){const n=Array.isArray(t.contentBoxSize)?t.contentBoxSize[0]:t.contentBoxSize;this.scrollDistance=.6*n.inlineSize}else this.scrollDistance=.6*t.contentRect.width})});s.observe(this),this.addEventListener("keydown",this.handleKeyDown),this.navButtonRight.addEventListener("click",this.scrollRight),this.navButtonLeft.addEventListener("click",this.scrollLeft),this.indicatorsContainer.addEventListener("click",this.handleIndicatorClick)}attributeChangedCallback(t,n,e){n!==e&&("indicator"===t&&(this.showIndicator=this.hasAttribute("indicator")),"autoplay"===t&&(this.hasAttribute("autoplay")?this.initialTimeout=setTimeout(()=>{this.isAutoPlaying=!0,this.autoPlay()},this.autoPlayInterval):(this.isAutoPlaying=!1,clearTimeout(this.autoPlayTimeout),clearTimeout(this.initialTimeout))),"interval"===t&&(this.hasAttribute("interval")&&""!==this.getAttribute("interval").trim()?this.autoPlayInterval=Math.abs(parseInt(this.getAttribute("interval").trim())):this.autoPlayInterval=5e3))}disconnectedCallback(){this.navButtonRight.removeEventListener("click",this.scrollRight),this.navButtonLeft.removeEventListener("click",this.scrollLeft),this.indicatorsContainer.removeEventListener("click",this.handleIndicatorClick)}});
\ No newline at end of file
+const smCarousel=document.createElement("template");smCarousel.innerHTML='\n\n
\n \n
\n \n
\n \n \n
\n',customElements.define("sm-carousel",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCarousel.content.cloneNode(!0)),this.isAutoPlaying=!1,this.autoPlayInterval=5e3,this.autoPlayTimeout,this.initialTimeout,this.activeSlideNum=0,this.carouselItems,this.indicators,this.showIndicator=!1,this.carousel=this.shadowRoot.querySelector(".carousel"),this.carouselContainer=this.shadowRoot.querySelector(".carousel-container"),this.carouselSlot=this.shadowRoot.querySelector("slot"),this.navButtonRight=this.shadowRoot.querySelector(".carousel__button--right"),this.navButtonLeft=this.shadowRoot.querySelector(".carousel__button--left"),this.indicatorsContainer=this.shadowRoot.querySelector(".indicators"),this.scrollLeft=this.scrollLeft.bind(this),this.scrollRight=this.scrollRight.bind(this),this.handleIndicatorClick=this.handleIndicatorClick.bind(this),this.showSlide=this.showSlide.bind(this),this.nextSlide=this.nextSlide.bind(this),this.autoPlay=this.autoPlay.bind(this),this.startAutoPlay=this.startAutoPlay.bind(this),this.stopAutoPlay=this.stopAutoPlay.bind(this)}static get observedAttributes(){return["indicator","autoplay","interval"]}scrollLeft(){this.carousel.scrollBy({left:-this.scrollDistance,behavior:"smooth"})}scrollRight(){this.carousel.scrollBy({left:this.scrollDistance,behavior:"smooth"})}showSlide(t){this.carousel.scrollTo({left:this.carouselItems[t].getBoundingClientRect().left-this.carousel.getBoundingClientRect().left+this.carousel.scrollLeft,behavior:"smooth"})}nextSlide(){if(!this.carouselItems)return;let t=this.activeSlideNum+1{this.autoPlay()},this.autoPlayInterval))}startAutoPlay(){this.setAttribute("autoplay","")}stopAutoPlay(){this.removeAttribute("autoplay")}createIndicator(t){let n=document.createElement("div");return n.classList.add("dot"),n.dataset.rank=t,n}handleIndicatorClick(t){if(t.target.closest(".dot")){const n=parseInt(t.target.closest(".dot").dataset.rank);this.activeSlideNum!==n&&this.showSlide(n)}}handleKeyDown(t){"ArrowLeft"===t.code?this.scrollRight():"ArrowRight"===t.code&&this.scrollRight()}connectedCallback(){let t=document.createDocumentFragment();this.carouselSlot.addEventListener("slotchange",n=>{this.carouselItems=this.carouselSlot.assignedElements(),this.carouselItems.forEach(t=>e.observe(t)),this.carouselItems.length>0?(i.observe(this.carouselItems[0]),o.observe(this.carouselItems[this.carouselItems.length-1])):(navButtonLeft.classList.add("hide"),navButtonRight.classList.add("hide"),i.disconnect(),o.disconnect()),this.showIndicator&&(this.indicatorsContainer.innerHTML="",this.carouselItems.forEach((n,e)=>{t.append(this.createIndicator(e)),n.dataset.rank=e}),this.indicatorsContainer.append(t),this.indicators=this.indicatorsContainer.children)});const n={threshold:.9,root:this},e=new IntersectionObserver(t=>{t.forEach(t=>{if(this.showIndicator){const n=parseInt(t.target.dataset.rank);t.isIntersecting?(this.indicators[n].classList.add("active"),this.activeSlideNum=n):this.indicators[n].classList.remove("active")}})},n),i=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting?this.navButtonLeft.classList.add("hide"):this.navButtonLeft.classList.remove("hide")})},n),o=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting?this.navButtonRight.classList.add("hide"):this.navButtonRight.classList.remove("hide")})},n),s=new ResizeObserver(t=>{t.forEach(t=>{if(t.contentBoxSize){const n=Array.isArray(t.contentBoxSize)?t.contentBoxSize[0]:t.contentBoxSize;this.scrollDistance=.6*n.inlineSize}else this.scrollDistance=.6*t.contentRect.width})});s.observe(this),this.addEventListener("keydown",this.handleKeyDown),this.navButtonRight.addEventListener("click",this.scrollRight),this.navButtonLeft.addEventListener("click",this.scrollLeft),this.indicatorsContainer.addEventListener("click",this.handleIndicatorClick)}attributeChangedCallback(t,n,e){n!==e&&("indicator"===t&&(this.showIndicator=this.hasAttribute("indicator")),"autoplay"===t&&(this.hasAttribute("autoplay")?this.initialTimeout=setTimeout(()=>{this.isAutoPlaying=!0,this.autoPlay()},this.autoPlayInterval):(this.isAutoPlaying=!1,clearTimeout(this.autoPlayTimeout),clearTimeout(this.initialTimeout))),"interval"===t&&(this.hasAttribute("interval")&&""!==this.getAttribute("interval").trim()?this.autoPlayInterval=Math.abs(parseInt(this.getAttribute("interval").trim())):this.autoPlayInterval=5e3))}disconnectedCallback(){this.navButtonRight.removeEventListener("click",this.scrollRight),this.navButtonLeft.removeEventListener("click",this.scrollLeft),this.indicatorsContainer.removeEventListener("click",this.handleIndicatorClick)}});
\ No newline at end of file
diff --git a/components/dist/hamburger-menu.js b/components/dist/hamburger-menu.js
index e4acb95..077337f 100644
--- a/components/dist/hamburger-menu.js
+++ b/components/dist/hamburger-menu.js
@@ -15,7 +15,7 @@ hamburgerMenu.innerHTML = `
overflow-y: auto;
--accent-color: #4d2588;
--text-color: 17, 17, 17;
- --background-color: inherit;
+ --background-color: 255, 255, 255;
--padding: 0 0 3rem 0;
--backdrop-color: rgba(0,0,0,0.5);
}
@@ -40,7 +40,7 @@ hamburgerMenu.innerHTML = `
overflow-y: auto;
width: calc(100% - 4rem);
transition: transform 0.3s;
- background-color: var(--background-color);
+ background-color: rgba(var(--background-color), 1);
box-shadow: 0.5rem 0 2rem rgba(0,0,0, 0.1);
z-index: 1;
}
diff --git a/components/dist/hamburger-menu.min.js b/components/dist/hamburger-menu.min.js
index 6fedc5c..dc783f2 100644
--- a/components/dist/hamburger-menu.min.js
+++ b/components/dist/hamburger-menu.min.js
@@ -1 +1 @@
-const hamburgerMenu=document.createElement("template");hamburgerMenu.innerHTML='\n\n\n\n';class HamburgerMenu extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(hamburgerMenu.content.cloneNode(!0)),this.resumeScrolling=this.resumeScrolling.bind(this),this.open=this.open.bind(this),this.close=this.close.bind(this),this.sideNav=this.shadowRoot.querySelector(".side-nav"),this.backdrop=this.shadowRoot.querySelector(".backdrop"),this.isOpen=!1,this.animeOptions={duration:300,easing:"ease"}}static get observedAttributes(){return["open"]}resumeScrolling(){const n=document.body.style.top;window.scrollTo(0,-1*parseInt(n||"0")),setTimeout(()=>{document.body.style.overflow="auto",document.body.style.top="initial"},300)}open(){this.isOpen||(document.body.style.overflow="hidden",document.body.style.top=`-${window.scrollY}px`,this.classList.remove("hide"),this.sideNav.classList.add("reveal"),this.backdrop.classList.remove("hide"),this.backdrop.animate([{opacity:0},{opacity:1}],this.animeOptions).onfinish=(()=>{this.isOpen=!0,this.setAttribute("open","")}))}close(){this.isOpen&&(this.sideNav.classList.remove("reveal"),this.backdrop.animate([{opacity:1},{opacity:0}],this.animeOptions).onfinish=(()=>{this.backdrop.classList.add("hide"),this.classList.add("hide"),this.isOpen=!1,this.removeAttribute("open")}))}connectedCallback(){this.backdrop.addEventListener("click",this.close);const n=new ResizeObserver(n=>{window.innerWidth<640&&this.isOpen?this.classList.remove("hide"):this.classList.add("hide"),window.innerWidth>640&&this.classList.remove("hide")});n.observe(this)}disconnectedCallback(){this.backdrop.removeEventListener("click",this.close)}attributeChangedCallback(n,e,t){"open"===n&&this.hasAttribute("open")&&this.open()}}window.customElements.define("hamburger-menu",HamburgerMenu);
\ No newline at end of file
+const hamburgerMenu=document.createElement("template");hamburgerMenu.innerHTML='\n\n\n\n';class HamburgerMenu extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(hamburgerMenu.content.cloneNode(!0)),this.resumeScrolling=this.resumeScrolling.bind(this),this.open=this.open.bind(this),this.close=this.close.bind(this),this.sideNav=this.shadowRoot.querySelector(".side-nav"),this.backdrop=this.shadowRoot.querySelector(".backdrop"),this.isOpen=!1,this.animeOptions={duration:300,easing:"ease"}}static get observedAttributes(){return["open"]}resumeScrolling(){const n=document.body.style.top;window.scrollTo(0,-1*parseInt(n||"0")),setTimeout(()=>{document.body.style.overflow="auto",document.body.style.top="initial"},300)}open(){this.isOpen||(document.body.style.overflow="hidden",document.body.style.top=`-${window.scrollY}px`,this.classList.remove("hide"),this.sideNav.classList.add("reveal"),this.backdrop.classList.remove("hide"),this.backdrop.animate([{opacity:0},{opacity:1}],this.animeOptions).onfinish=(()=>{this.isOpen=!0,this.setAttribute("open","")}))}close(){this.isOpen&&(this.sideNav.classList.remove("reveal"),this.backdrop.animate([{opacity:1},{opacity:0}],this.animeOptions).onfinish=(()=>{this.backdrop.classList.add("hide"),this.classList.add("hide"),this.isOpen=!1,this.removeAttribute("open")}))}connectedCallback(){this.backdrop.addEventListener("click",this.close);const n=new ResizeObserver(n=>{window.innerWidth<640&&this.isOpen?this.classList.remove("hide"):this.classList.add("hide"),window.innerWidth>640&&this.classList.remove("hide")});n.observe(this)}disconnectedCallback(){this.backdrop.removeEventListener("click",this.close)}attributeChangedCallback(n,e,t){"open"===n&&this.hasAttribute("open")&&this.open()}}window.customElements.define("hamburger-menu",HamburgerMenu);
\ No newline at end of file
diff --git a/components/index.html b/components/index.html
index 792e434..3ae560f 100644
--- a/components/index.html
+++ b/components/index.html
@@ -77,10 +77,14 @@
Overview
- Component-based design is the cornerstone of the modern UI development process. With rise of more UI frameworks every day, the web platform has a serious issue of fragmentation and portability.
+ Component-based design is the cornerstone of the modern UI development process. With rise of
+ more UI frameworks every day, the web platform has a serious issue of fragmentation and
+ portability.
- Web components to the rescue! This is the collection of web components (WC here forward) that we use at RanchiMall, especially since we are a framework-less development environment so this was a logical choice.
+ Web components to the rescue! This is the collection of web components (WC here forward) that we
+ use at RanchiMall, especially since we are a framework-less development environment so this was
+ a logical choice.
Just download the components you like, link them with a script tag and drop it in HTML done!
@@ -99,17 +103,20 @@
Quick Start
- To start using these components, Select the ones you want to add to your project. You can un-check 'get minified' to get the readable code.
+ To start using these components, Select the ones you want to add to your project. You can
+ un-check 'get minified' to get the readable code.
- Now you can download or copy the source code for selected components.
+ Now you can download or copy the source code for selected components.
You might get a warning while downloading like this file is not safe,
- please allow the download as this is caused when downloading files with '.js' extension. These components are 100% safe to use.
+ please allow the download as this is caused when downloading files with '.js' extension.
+ These components are 100% safe to use.
- Link the downloaded js with <script src=".../components.js"></script> at bottom of your HTML file just before </body> tag.
+ Link the downloaded js with <script src=".../components.js"></script>
+ at bottom of your HTML file just before </body> tag.
@@ -130,72 +137,66 @@
Global styling
-
These components use CSS variables to customize styling. they share some CSS variables that make global styling easier.
+
These components use CSS variables to customize styling. they share some CSS
+ variables that make global styling easier.
Some common CSS variables and their use
-
-
-
-
Variable
-
Use
-
-
-
-
-
--accent-color
-
Color which will be used for denoting active state
-
-
-
--text-color
-
- default text color for all components.
- ( Use comma separated rgb values. e.g 17, 17, 17 )
-
-
-
-
--background-color
-
- default background color for all components.
- ( Use comma separated rgb values. e.g 255, 255, 255 )
-
-
-
-
--danger-color
-
Used for error/invalid state
-
-
-
+
+
+
Variable
+
Use
+
+
+
--accent-color
+
Color which will be used for denoting active state
+
+
+
--text-color
+
+ default text color for all components.
+ ( Use comma separated rgb values. e.g 17, 17, 17 )
+
+
+
+
--background-color
+
+ default background color for all components.
+ ( Use comma separated rgb values. e.g 255, 255, 255 )
+
+
+
+
--danger-color
+
Used for error/invalid state
+
+
Buttons
+ Default button
sm-button has 3 variants that define how the button looks.
- Button is disabled by default. all the interactions are disabled
-
-
-
-
type (string)
-
- Has values submitreset
- Can only used withing sm-form to submit or reset the form.
-
-
-
-
+
+
+
Attribute
+
Description
+
+
+
disabled (boolean)
+
+ Button is disabled by default. all the interactions are disabled
+
+
+
+
type (string)
+
+ Has values submitreset
+ Can only used withing sm-form to submit or reset the form.
+
+
+
Styling
CSS variables used to style this component
-
-
-
-
Variable
-
Description
-
-
-
-
-
--background
-
- Define background of button. accepts all values of CSS background property
-
-
-
-
--border-radius
-
- Set curvature at button corners
-
-
-
-
--padding
-
- Specify padding of button
-
-
-
-
+
+
+
Variable
+
Description
+
+
+
--background
+
+ Define background of button. accepts all values of CSS background property
+
+
+
+
--border-radius
+
+ Set curvature at button corners
+
+
+
+
--padding
+
+ Specify padding of button
+
+
+
Carousel
Carousel is a very common UI component primarily used to display images or slides.
- This carousel switches user interactions based on type of input devices present. For hover capable devices slides can be scrolled with buttons and on
+ This carousel switches user interactions based on type of input devices present. For hover capable
+ devices slides can be scrolled with buttons and on
touch enabled devices swipe can be used.
Interactive demo
@@ -306,74 +300,67 @@
Custom attributes
These attributes cane used to customize carousel behaviour and features
-
-
-
-
Attribute
-
Description
-
-
-
-
-
align-items
-
- Has values start
- centerend
- Specifies how carousel items should align. default is center.
-
-
-
-
indicator (boolean)
-
- if added carousel shows dot indicators of carousel items.
-
-
-
-
+
+
+
Attribute
+
Description
+
+
+
align-items
+
+ Has values start
+ centerend
+ Specifies how carousel items should align. default is center.
+
+
+
+
indicator (boolean)
+
+ if added carousel shows dot indicators of carousel items.
+
+
+
Styling
CSS variables used to style this component
-
-
-
-
Variable
-
Description
-
-
-
-
-
--active-indicator-color
-
- Defines background color of active slide indicator
-
-
-
-
--nav-background-color
-
- Defines background color of carousel navigation buttons
-
-
-
-
--nav-box-shadow
-
- Defines box shadow of carousel navigation buttons
-
-
-
-
--nav-icon-fill
-
- Defines fill of arrow icon on carousel navigation buttons
-
-
-
-
+
+
+
Variable
+
Description
+
+
+
--active-indicator-color
+
+ Defines background color of active slide indicator
+
+
+
+
--nav-background-color
+
+ Defines background color of carousel navigation buttons
+
+
+
+
--nav-box-shadow
+
+ Defines box shadow of carousel navigation buttons
+
+
+
+
--nav-icon-fill
+
+ Defines fill of arrow icon on carousel navigation buttons
+
+
+
Checkbox
sm-checkbox supports all the attributes of native HTML5 checkbox
- linking some HTML element with sm-checbox using label tag won't work.
+ linking some HTML element with sm-checbox using label tag won't work.
Add the element inside the opening and closing checkbox tag.
Interactive demo
@@ -386,7 +373,7 @@
States
Disabled
To disable the checkbox add disabled attribute.
-
+
Disabled checkbox
@@ -416,65 +403,57 @@
Attributes
All the native HTML checkbox attributes are valid
-
-
-
-
Attribute
-
Description
-
-
-
-
-
checked (boolean)
-
- Sets checked state as default if added
-
-
-
-
disabled (boolean)
-
- Checkbox is disabled by default. all the interactions are disabled
-
-
-
-
value (string)
-
- Sets value of checkbox which can be accessed by value property with JS
-
-
-
-
+
+
+
Attribute
+
Description
+
+
+
checked (boolean)
+
+ Sets checked state as default if added
+
+
+
+
disabled (boolean)
+
+ Checkbox is disabled by default. all the interactions are disabled
+
+
+
+
value (string)
+
+ Sets value of checkbox which can be accessed by value property with JS
+
+
+
Styling
CSS variables used to style this component
-
-
-
-
Variable
-
Description
-
-
-
-
-
--border-radius
-
- Defines border-radius of checkbox square
-
-
-
-
--height
-
- Defines height of checkbox
-
-
-
-
--width
-
- Defines width of checkbox
-
-
-
-
+
+
+
Variable
+
Description
+
+
+
--border-radius
+
+ Defines border-radius of checkbox square
+
+
+
+
--height
+
+ Defines height of checkbox
+
+
+
+
--width
+
+ Defines width of checkbox
+
+
+
@@ -499,7 +478,8 @@
To start using SM Components
-
+
+ Submit
@@ -515,8 +495,8 @@
- <sm-select> is very similar to starndatd HTML5 select and it's markup stucture is
+ <sm-select> is very similar to starndatd HTML5 select and it's
+ markup stucture is
also identical.