You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2021/01/04 11:04:27 UTC

[royale-asjs] branch develop updated: New Jewel constrols: SwitchCheckBox and SwitchRadioButton

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3e67b84  New Jewel constrols: SwitchCheckBox and SwitchRadioButton
3e67b84 is described below

commit 3e67b84a3cbeabd0ad4b660ae4b88485256350cc
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Mon Jan 4 12:04:16 2021 +0100

    New Jewel constrols: SwitchCheckBox and SwitchRadioButton
---
 .../projects/Jewel/src/main/resources/defaults.css |  45 +++++++
 .../Jewel/src/main/resources/jewel-manifest.xml    |   2 +
 .../royale/org/apache/royale/jewel/RadioButton.as  |   3 +-
 .../org/apache/royale/jewel/SwitchCheckBox.as      | 121 +++++++++++++++++++
 .../org/apache/royale/jewel/SwitchRadioButton.as   | 129 +++++++++++++++++++++
 .../Jewel/src/main/sass/components/_checkbox.sass  |  50 ++++++++
 .../JewelTheme/src/main/resources/defaults.css     |  42 ++++++-
 .../main/sass/components-primary/_checkbox.sass    |  62 +++++++++-
 8 files changed, 446 insertions(+), 8 deletions(-)

diff --git a/frameworks/projects/Jewel/src/main/resources/defaults.css b/frameworks/projects/Jewel/src/main/resources/defaults.css
index e278045..db6d871 100644
--- a/frameworks/projects/Jewel/src/main/resources/defaults.css
+++ b/frameworks/projects/Jewel/src/main/resources/defaults.css
@@ -385,6 +385,51 @@ j|ToggleButtonBar {
   width: inherit;
 }
 
+.jewel.switch {
+  display: inline-flex;
+  position: relative;
+  height: auto;
+}
+.jewel.switch input {
+  -webkit-appearance: none;
+  -moz-appearance: none;
+  -o-appearance: none;
+  -ms-appearance: none;
+  appearance: none;
+  display: inline-flex;
+  opacity: 0;
+  width: 44px;
+  height: 24px;
+  margin: 0;
+  padding: 0;
+}
+.jewel.switch input[disabled] + span {
+  cursor: unset;
+}
+.jewel.switch .switch {
+  position: absolute;
+  cursor: pointer;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+  width: 44px;
+  height: 24px;
+}
+.jewel.switch .switch::before {
+  position: absolute;
+  content: "";
+  height: 20px;
+  width: 20px;
+  left: 2px;
+  bottom: 2px;
+}
+.jewel.switch .label {
+  cursor: pointer;
+  margin: auto;
+  width: inherit;
+}
+
 .jewel.combobox {
   display: inline-flex;
 }
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 5ca4d25..88ef7a9 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -79,7 +79,9 @@
     <component id="HSlider" class="org.apache.royale.jewel.HSlider"/>
     <component id="VSlider" class="org.apache.royale.jewel.VSlider"/>
     <component id="RadioButton" class="org.apache.royale.jewel.RadioButton"/>
+    <component id="SwitchRadioButton" class="org.apache.royale.jewel.SwitchRadioButton"/>
     <component id="CheckBox" class="org.apache.royale.jewel.CheckBox"/>
+    <component id="SwitchCheckBox" class="org.apache.royale.jewel.SwitchCheckBox"/>
     <component id="Alert" class="org.apache.royale.jewel.Alert"/>
     <component id="TitleBar" class="org.apache.royale.jewel.TitleBar"/>
     <component id="List" class="org.apache.royale.jewel.List"/>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/RadioButton.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/RadioButton.as
index de4eb69..f877303 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/RadioButton.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/RadioButton.as
@@ -42,7 +42,8 @@ package org.apache.royale.jewel
      *  
      *  A RadioButton consists of a circle and, typically, text that clearly communicates a
      *  condition that will be set when the user clicks or touches it. Radio buttons
-     *  always appear in groups of two or more with the same <code>groupName</code> propert. 
+     *  always appear in groups of two or more with the same <code>groupName</code> property.
+     *   
      *  While they can be individually selected, can only be deselected by selecting 
      *  a different RadioButton in the same group (which deselects the rest of RadioButton).
      *  
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/SwitchCheckBox.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/SwitchCheckBox.as
new file mode 100644
index 0000000..cb37524
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/SwitchCheckBox.as
@@ -0,0 +1,121 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.jewel
+{
+    COMPILE::JS
+    {
+    import org.apache.royale.core.WrappedHTMLElement;
+    import org.apache.royale.html.util.addElementToWrapper;
+    }
+
+    /**
+     *  The Jewel SwitchCheckBox consists of a lever that can be moved back and forth indicating a binary condition
+     *  that will be set or unset when the user clicks or touches it. It can contain an optional label.
+     *  
+     *  When a user clicks or touches this control or its associated text, the SwitchCheckBox changes 
+     *  its state from `active` to `inactive` or from `inactive` to `active`, communicating
+     *  clearly the binary condition.
+     *  
+     *  SwitchCheckBox can appear in groups (but not necesarily), and can be
+     *  selected and deselected individually.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.8
+     */
+    public class SwitchCheckBox extends CheckBox
+	{
+        /**
+         *  Constructor.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+		public function SwitchCheckBox()
+		{
+			super();
+            typeNames = "jewel switch";
+		}
+
+        COMPILE::JS
+		private var _spanSwitch:HTMLSpanElement;
+		/**
+         *  the span for the switch
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+		COMPILE::JS
+		public function get spanSwitch():HTMLSpanElement {
+			return _spanSwitch;
+		} 
+		COMPILE::JS
+		public function set spanSwitch(value:HTMLSpanElement):void {
+			_spanSwitch = value;
+		}
+
+        /**
+         * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
+         * @royaleignorecoercion HTMLInputElement
+         * @royaleignorecoercion HTMLSpanElement
+         */
+        COMPILE::JS
+        override protected function createElement():WrappedHTMLElement
+        {
+            input = addElementToWrapper(this,'input') as HTMLInputElement;
+            input.type = 'checkbox';
+            spanSwitch = document.createElement('span') as HTMLSpanElement;
+            spanSwitch.className = 'switch';
+            spanLabel = document.createElement('span') as HTMLSpanElement;
+            spanLabel.className = 'label';
+            positioner = document.createElement('label') as WrappedHTMLElement;   
+            return element;
+        }
+
+        COMPILE::JS
+        private var _positioner:WrappedHTMLElement;
+        /**
+         *  @copy org.apache.royale.core.IUIBase#positioner
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        COMPILE::JS
+		override public function get positioner():WrappedHTMLElement
+		{
+			return _positioner;
+		}
+        COMPILE::JS
+		override public function set positioner(value:WrappedHTMLElement):void
+		{
+			_positioner = value;
+            _positioner.royale_wrapper = this;
+			_positioner.appendChild(element);
+            _positioner.appendChild(spanSwitch);
+            _positioner.appendChild(spanLabel);
+		}
+	}
+}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/SwitchRadioButton.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/SwitchRadioButton.as
new file mode 100644
index 0000000..9cbd29a
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/SwitchRadioButton.as
@@ -0,0 +1,129 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.jewel
+{
+    COMPILE::JS
+    {
+    import org.apache.royale.core.WrappedHTMLElement;
+    import org.apache.royale.html.util.addElementToWrapper;
+    }
+    
+    /**
+     *  The Jewel SwitchRadioButton control lets the user make a single choice within a set of mutually exclusive choices.
+     *  
+     *  A SwitchRadioButton of a lever that can be moved back and forth indicating a binary condition
+     *  that will be set or unset when the user clicks or touches it. SwitchRadioButtons
+     *  always appear in groups of two or more with the same <code>groupName</code> property.
+     *   
+     *  While they can be individually selected, can only be deselected by selecting 
+     *  a different SwitchRadioButton in the same group (which deselects the rest of SwitchRadioButton).
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.8
+     */
+    public class SwitchRadioButton extends RadioButton
+	{
+        /**
+         *  Constructor.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+		public function SwitchRadioButton()
+		{
+			super();
+            typeNames = "jewel switch";
+		}
+
+        COMPILE::JS
+		private var _spanSwitch:HTMLSpanElement;
+		/**
+         *  the span for the switch
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+		COMPILE::JS
+		public function get spanSwitch():HTMLSpanElement {
+			return _spanSwitch;
+		} 
+		COMPILE::JS
+		public function set spanSwitch(value:HTMLSpanElement):void {
+			_spanSwitch = value;
+		}
+
+        /**
+         * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
+         * @royaleignorecoercion HTMLInputElement
+         * @royaleignorecoercion HTMLSpanElement
+         * @royaleignorecoercion Text
+         */
+        COMPILE::JS
+        override protected function createElement():WrappedHTMLElement
+        {
+            icon = addElementToWrapper(this, 'input') as HTMLInputElement;
+            icon.type = 'radio';
+            icon.id = '_radio_' + Math.random();
+            icon.value = String(value);
+            
+            spanSwitch = document.createElement('span') as HTMLSpanElement;
+            spanSwitch.className = 'switch';
+
+            textNode = document.createTextNode('') as Text;
+            spanLabel = document.createElement('span') as HTMLSpanElement;
+            spanLabel.className = 'label';
+            spanLabel.appendChild(textNode);
+            
+            positioner = document.createElement('label') as WrappedHTMLElement;
+            
+            return element;
+        }
+
+        COMPILE::JS
+        private var _positioner:WrappedHTMLElement;
+        /**
+         *  @copy org.apache.royale.core.IUIBase#positioner
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        COMPILE::JS
+		override public function get positioner():WrappedHTMLElement
+		{
+			return _positioner;
+		}
+        COMPILE::JS
+		override public function set positioner(value:WrappedHTMLElement):void
+		{
+			_positioner = value;
+            _positioner.royale_wrapper = this;
+			_positioner.appendChild(element);
+            _positioner.appendChild(spanSwitch);
+            _positioner.appendChild(spanLabel);
+		}
+	}
+}
diff --git a/frameworks/projects/Jewel/src/main/sass/components/_checkbox.sass b/frameworks/projects/Jewel/src/main/sass/components/_checkbox.sass
index f7d6969..d893c8c 100644
--- a/frameworks/projects/Jewel/src/main/sass/components/_checkbox.sass
+++ b/frameworks/projects/Jewel/src/main/sass/components/_checkbox.sass
@@ -99,3 +99,53 @@ j|CheckBox
 		IBeadView:  ClassReference("org.apache.royale.jewel.beads.views.CheckBoxView")
 		//font-size: 11px
 		//font-family: Arial
+
+// Jewel CheckBoxSwitch
+
+// CheckBoxSwitch variables
+$switch-button-size: 24px
+$switch-button-offset: 2px
+$switch-inner-size: $switch-button-size - (2 * $switch-button-offset)
+
+.jewel.switch
+	display: inline-flex
+	position: relative
+	// width: 0
+	height: auto
+
+	input
+		+appear(none)
+		display: inline-flex
+		opacity: 0
+		width: ($switch-button-size * 2) - ($switch-button-offset * 2)
+		height: $switch-button-size
+		margin: 0
+		padding: 0
+	
+		&[disabled]
+			& + span
+				cursor: unset
+	
+	.switch
+		position: absolute
+		cursor: pointer
+		top: 0
+		left: 0
+		right: 0
+		bottom: 0
+		width: ($switch-button-size * 2) - ($switch-button-offset * 2)
+		height: $switch-button-size
+		
+		&::before
+			position: absolute
+			content: ""
+			height: $switch-inner-size
+			width: $switch-inner-size
+			left: $switch-button-offset
+			bottom: $switch-button-offset
+
+	.label
+		cursor: pointer
+
+		margin: auto
+		width: inherit		
\ No newline at end of file
diff --git a/frameworks/themes/JewelTheme/src/main/resources/defaults.css b/frameworks/themes/JewelTheme/src/main/resources/defaults.css
index d768e91..381c8b7 100644
--- a/frameworks/themes/JewelTheme/src/main/resources/defaults.css
+++ b/frameworks/themes/JewelTheme/src/main/resources/defaults.css
@@ -420,14 +420,14 @@ j|CardActions {
   border: 1px solid #0f88d1;
   border-radius: 3px;
 }
+.jewel.checkbox input[disabled] + span {
+  color: silver;
+}
 .jewel.checkbox input[disabled] + span::before {
   background: #f3f3f3;
   border: 1px solid #d9d9d9;
   border-radius: 3px;
 }
-.jewel.checkbox input[disabled] + span {
-  color: silver;
-}
 .jewel.checkbox input[disabled] + span::after {
   background: url("data:image/svg+xml,%3Csvg viewBox='0 0 22 22' version='1.1' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='0' width='22' height='22' fill-opacity='0'/%3E%3Cpolygon fill='%23cccccc' points='3.50018311 12.4854126 8.48547363 17.4989624 18.4641113 7.47589111 15.5010376 4.51739502 8.48547363 11.5650024 6.52087402 9.47265625'/%3E%3C/svg%3E") no-repeat center center;
 }
@@ -435,6 +435,42 @@ j|CardActions {
   padding-left: 8px;
 }
 
+.jewel.switch input:checked + .switch {
+  background-color: #3CADF1;
+}
+.jewel.switch input:focus + .switch {
+  box-shadow: 0 0 1px #3CADF1;
+}
+.jewel.switch input:checked + .switch::before {
+  transform: translateX(20px);
+}
+.jewel.switch input[disabled]:checked + .switch {
+  background-color: silver;
+}
+.jewel.switch input[disabled] + .switch {
+  color: silver;
+}
+.jewel.switch input[disabled] + .switch::before {
+  background: #f3f3f3;
+}
+.jewel.switch .switch {
+  background-color: #d9d9d9;
+  transition: 0.4s;
+  border-radius: 20px;
+}
+.jewel.switch .switch::before {
+  height: 20px;
+  width: 20px;
+  left: 2px;
+  bottom: 2px;
+  background-color: white;
+  transition: 0.4s;
+  border-radius: 50%;
+}
+.jewel.switch .label {
+  padding-left: 8px;
+}
+
 .jewel.combobox .jewel.textinput input {
   border-radius: 0.25rem 0px 0px 0.25rem;
 }
diff --git a/frameworks/themes/JewelTheme/src/main/sass/components-primary/_checkbox.sass b/frameworks/themes/JewelTheme/src/main/sass/components-primary/_checkbox.sass
index 59d651a..34ad2c4 100644
--- a/frameworks/themes/JewelTheme/src/main/sass/components-primary/_checkbox.sass
+++ b/frameworks/themes/JewelTheme/src/main/sass/components-primary/_checkbox.sass
@@ -60,6 +60,9 @@ $checkbox-label-font-size: 16px
 
         &[disabled]
 
+            & + span
+                color: $disabled-font-color
+
             & + span::before
                 background: $disabled-color
                 @if $flat
@@ -68,9 +71,6 @@ $checkbox-label-font-size: 16px
                     border: 1px solid $disabled-border-color// .094em
                 border-radius: $checkbox-border-radius
 
-            & + span
-                color: $disabled-font-color
-
             & + span::after
                 background: encodeSVG("<svg viewBox='0 0 22 22' version='1.1' xmlns='http://www.w3.org/2000/svg'><rect x='0' y='0' width='22' height='22' fill-opacity='0'/><polygon fill='#{darken($disabled-color, 15%)}' points='3.50018311 12.4854126 8.48547363 17.4989624 18.4641113 7.47589111 15.5010376 4.51739502 8.48547363 11.5650024 6.52087402 9.47265625'/></svg>") no-repeat center center
 
@@ -78,4 +78,58 @@ $checkbox-label-font-size: 16px
     span
         padding-left: $checkbox-label-separation
         //font-size: $checkbox-label-font-size
-        
\ No newline at end of file
+
+
+// Jewel CheckBoxSwitch
+
+// CheckBoxSwitch variables
+$switch-button-size: 24px
+$switch-button-offset: 2px
+$switch-inner-size: $switch-button-size - (2 * $switch-button-offset)
+$switch-button-border-radius: 50%
+$switch-transition-delay: .4s
+$switch-label-separation: 8px
+
+.jewel.switch
+
+    input
+        &:checked 
+            + .switch
+                background-color: $primary-color
+
+        &:focus
+            + .switch
+                box-shadow: 0 0 1px $primary-color
+
+        &:checked 
+            + .switch::before
+                transform: translateX($switch-inner-size)
+
+        &[disabled]
+            &:checked 
+                + .switch
+                    background-color: $disabled-font-color
+
+            & + .switch
+                color: $disabled-font-color
+
+            & + .switch::before
+                background: $disabled-color
+
+    .switch
+        background-color: $default-color
+        transition: $switch-transition-delay
+
+        border-radius: $switch-inner-size
+
+    .switch::before
+        height: $switch-inner-size
+        width: $switch-inner-size
+        left: $switch-button-offset
+        bottom: $switch-button-offset
+        background-color: lighten($primary-color, 50%)
+        transition: $switch-transition-delay
+        border-radius: $switch-button-border-radius
+	
+    .label
+        padding-left: $switch-label-separation
\ No newline at end of file