From 80beeba1e202388c4b9fc3f7ef24c2c429d50210 Mon Sep 17 00:00:00 2001
From: Alex Natalia <38787212+alexnatalia@users.noreply.github.com>
Date: Wed, 14 Oct 2020 15:29:58 +0300
Subject: [PATCH 1/3] Switch Component Addition (#65)
* Switch Component: Added Component and Story.
---
src/components/Switch/SSwitch.vue | 93 +++++++++++++++++++++++++++++++
src/components/Switch/index.ts | 3 +
src/components/index.ts | 2 +
src/index.ts | 3 +
src/stories/SSwitch.stories.ts | 61 ++++++++++++++++++++
src/styles/index.scss | 1 +
src/styles/switch.scss | 10 ++++
src/types/components.ts | 1 +
8 files changed, 174 insertions(+)
create mode 100644 src/components/Switch/SSwitch.vue
create mode 100644 src/components/Switch/index.ts
create mode 100644 src/stories/SSwitch.stories.ts
create mode 100644 src/styles/switch.scss
diff --git a/src/components/Switch/SSwitch.vue b/src/components/Switch/SSwitch.vue
new file mode 100644
index 00000000..37bdb26c
--- /dev/null
+++ b/src/components/Switch/SSwitch.vue
@@ -0,0 +1,93 @@
+
+
+
+
+
+
+
diff --git a/src/components/Switch/index.ts b/src/components/Switch/index.ts
new file mode 100644
index 00000000..2040039d
--- /dev/null
+++ b/src/components/Switch/index.ts
@@ -0,0 +1,3 @@
+import SSwitch from './SSwitch.vue'
+
+export { SSwitch }
diff --git a/src/components/index.ts b/src/components/index.ts
index 573e5ba2..b5be4cd7 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -23,6 +23,7 @@ import { SInput, SJsonInput } from './Input'
import { SMain } from './Layout/Main'
import { SMenu, SMenuItem, SMenuItemGroup, SSubmenu } from './Menu'
import { SPagination } from './Pagination'
+import { SSwitch } from './Switch'
import { SRadio } from './Radio'
import { SRow } from './Layout/Row'
import { SScrollSectionItem, SScrollSections } from './ScrollSections'
@@ -69,6 +70,7 @@ export {
SScrollSections,
SSelect,
SSubmenu,
+ SSwitch,
STab,
STabs,
STable,
diff --git a/src/index.ts b/src/index.ts
index ba537aae..c012779e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -38,6 +38,7 @@ import {
SScrollSections,
SSelect,
SSubmenu,
+ SSwitch,
STab,
STabs,
STable,
@@ -87,6 +88,7 @@ const components = [
{ component: SScrollSections, name: Components.SScrollSections },
{ component: SSelect, name: Components.SSelect },
{ component: SSubmenu, name: Components.SSubmenu },
+ { component: SSwitch, name: Components.SSwitch },
{ component: STab, name: Components.STab },
{ component: STabs, name: Components.STabs },
{ component: STable, name: Components.STable },
@@ -152,6 +154,7 @@ export {
SScrollSections,
SSelect,
SSubmenu,
+ SSwitch,
STab,
STabs,
STable,
diff --git a/src/stories/SSwitch.stories.ts b/src/stories/SSwitch.stories.ts
new file mode 100644
index 00000000..7ad0ef19
--- /dev/null
+++ b/src/stories/SSwitch.stories.ts
@@ -0,0 +1,61 @@
+import { color, text, number, boolean, withKnobs } from '@storybook/addon-knobs'
+
+import { SSwitch } from '../components/Switch'
+
+export default {
+ component: SSwitch,
+ title: 'Design System/Components/Switch',
+ decorators: [withKnobs],
+ excludeStories: /.*Data$/
+}
+
+export const configurable = () => ({
+ components: { SSwitch },
+ template: `
+ changeValue = value"
+ />
+
+ v-model="{{ modelValue }}", @change="{{ changeValue }}"
+
+
`,
+ data: () => ({
+ modelValue: true,
+ changeValue: true
+ }),
+ props: {
+ activeColor: {
+ default: color('Active Background Color', 'rgb(208, 2, 27)')
+ },
+ inactiveColor: {
+ default: color('Inactive Background Color', 'rgb(246, 204, 209)')
+ },
+ activeText: {
+ default: text('Active Text', '')
+ },
+ inactiveText: {
+ default: text('Inactive Text', '')
+ },
+ activeValue: {
+ default: text('Active Value', 'Active Value')
+ },
+ inactiveValue: {
+ default: text('Inactive Value', 'Inactive Value')
+ },
+ width: {
+ default: number('Width', 40)
+ },
+ disabled: {
+ default: boolean('Disabled', false)
+ }
+ }
+})
diff --git a/src/styles/index.scss b/src/styles/index.scss
index 9b2002d7..12bc8763 100644
--- a/src/styles/index.scss
+++ b/src/styles/index.scss
@@ -18,6 +18,7 @@
@import "./radio";
@import "./scroll-sections";
@import "./select";
+@import "./switch";
@import "./tabs";
@import "./table";
@import "./tooltip";
diff --git a/src/styles/switch.scss b/src/styles/switch.scss
new file mode 100644
index 00000000..7db1a641
--- /dev/null
+++ b/src/styles/switch.scss
@@ -0,0 +1,10 @@
+@import "./variables";
+
+.s-switch {
+ .el-switch__label {
+ color: var(--s-color-basic-black);
+ &.is-active {
+ color: var(--s-color-main-brand);
+ }
+ }
+}
diff --git a/src/types/components.ts b/src/types/components.ts
index 3c4d1a20..7c180c2f 100644
--- a/src/types/components.ts
+++ b/src/types/components.ts
@@ -36,6 +36,7 @@ export enum Components {
SScrollSections = 'SScrollSections',
SSelect = 'SSelect',
SSubmenu = 'SSubmenu',
+ SSwitch = 'SSwitch',
STab = 'STab',
STabs = 'STabs',
STable = 'STable',
From 067d76c03284306e3f709136119b91675353c4f8 Mon Sep 17 00:00:00 2001
From: Alex Natalia <38787212+alexnatalia@users.noreply.github.com>
Date: Tue, 20 Oct 2020 13:17:51 +0300
Subject: [PATCH 2/3] Slider component (#67)
Added Slider component and story.
---
package.json | 2 +-
src/components/Slider/SSlider.vue | 130 +++++++++++++++++++++
src/components/Slider/index.ts | 3 +
src/components/Switch/SSwitch.vue | 3 +-
src/components/index.ts | 2 +
src/index.ts | 3 +
src/stories/SSlider.stories.ts | 185 ++++++++++++++++++++++++++++++
src/styles/index.scss | 1 +
src/styles/slider.scss | 97 ++++++++++++++++
src/styles/variables.scss | 1 +
src/types/components.ts | 1 +
11 files changed, 425 insertions(+), 3 deletions(-)
create mode 100644 src/components/Slider/SSlider.vue
create mode 100644 src/components/Slider/index.ts
create mode 100644 src/stories/SSlider.stories.ts
create mode 100644 src/styles/slider.scss
diff --git a/package.json b/package.json
index d2d00eac..29ac3ab9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@soramitsu/soramitsu-js-ui",
- "version": "0.4.1",
+ "version": "0.4.2",
"private": false,
"publishConfig": {
"registry": "https://nexus.iroha.tech/repository/npm-soramitsu-private/"
diff --git a/src/components/Slider/SSlider.vue b/src/components/Slider/SSlider.vue
new file mode 100644
index 00000000..8baf9a3b
--- /dev/null
+++ b/src/components/Slider/SSlider.vue
@@ -0,0 +1,130 @@
+
+
+
+
+
+
+
diff --git a/src/components/Slider/index.ts b/src/components/Slider/index.ts
new file mode 100644
index 00000000..b78fc957
--- /dev/null
+++ b/src/components/Slider/index.ts
@@ -0,0 +1,3 @@
+import SSlider from './SSlider.vue'
+
+export { SSlider }
diff --git a/src/components/Switch/SSwitch.vue b/src/components/Switch/SSwitch.vue
index 37bdb26c..b490404f 100644
--- a/src/components/Switch/SSwitch.vue
+++ b/src/components/Switch/SSwitch.vue
@@ -1,7 +1,6 @@
diff --git a/src/components/Radio/index.ts b/src/components/Radio/index.ts
index ec804fcd..9392d611 100644
--- a/src/components/Radio/index.ts
+++ b/src/components/Radio/index.ts
@@ -1,4 +1,5 @@
import SRadio from './SRadio.vue'
+import SRadioGroup from './SRadioGroup.vue'
import { RadioSize } from './consts'
-export { SRadio, RadioSize }
+export { SRadio, SRadioGroup, RadioSize }
diff --git a/src/components/Slider/SSlider.vue b/src/components/Slider/SSlider.vue
index 8baf9a3b..53a018bb 100644
--- a/src/components/Slider/SSlider.vue
+++ b/src/components/Slider/SSlider.vue
@@ -29,6 +29,8 @@
import { Vue, Component, Prop, Ref, Watch } from 'vue-property-decorator'
import { ElSlider } from 'element-ui/types/slider'
+import { SliderInputSize } from './consts'
+
@Component
export default class SSlider extends Vue {
/**
@@ -68,9 +70,9 @@ export default class SSlider extends Vue {
*/
@Prop({ default: true, type: Boolean }) readonly showInputControls!: boolean
/**
- * Size of the input box
+ * Size of the input box. Possible values: `"big"`, `"medium"`, `"small"`, `"mini"`
*/
- @Prop({ default: 'small', type: String }) readonly inputSize!: 'large' | 'medium' | 'small' | 'mini'
+ @Prop({ default: SliderInputSize.SMALL, type: String }) readonly inputSize!: string
/**
* Debounce delay when typing, in milliseconds, works when show-input is true
*/
diff --git a/src/components/Slider/consts.ts b/src/components/Slider/consts.ts
new file mode 100644
index 00000000..3e4ca1e0
--- /dev/null
+++ b/src/components/Slider/consts.ts
@@ -0,0 +1,6 @@
+export enum SliderInputSize {
+ BIG = 'big',
+ MEDIUM = 'medium',
+ SMALL = 'small',
+ MINI = 'mini'
+}
diff --git a/src/components/Slider/index.ts b/src/components/Slider/index.ts
index b78fc957..67073618 100644
--- a/src/components/Slider/index.ts
+++ b/src/components/Slider/index.ts
@@ -1,3 +1,4 @@
import SSlider from './SSlider.vue'
+import { SliderInputSize } from './consts'
-export { SSlider }
+export { SSlider, SliderInputSize }
diff --git a/src/components/Switch/SSwitch.vue b/src/components/Switch/SSwitch.vue
index b490404f..e8b85bc4 100644
--- a/src/components/Switch/SSwitch.vue
+++ b/src/components/Switch/SSwitch.vue
@@ -2,8 +2,6 @@
({
components: { SRadio, SRow, SCol },
template: `
-
- changeValue = value"
- >
- {{ item.title }}
-
-
-
- v-model="{{ vModelValue }}", @change="{{ changeValue }}"
-
- `,
+
+ changeValue = value"
+ >
+ {{ item.title }}
+
+
+
+ v-model="{{ vModelValue }}", @change="{{ changeValue }}"
+
+ `,
data: () => ({
vModelValue: 'first',
changeValue: '',
@@ -55,16 +55,16 @@ export const configurable = () => ({
export const disabled = () => ({
components: { SRadio, SRow },
template: `
-
- {{ item.title }}
-
- `,
+
+ {{ item.title }}
+
+ `,
data: () => ({
model: 'first',
items: radioData
@@ -74,18 +74,51 @@ export const disabled = () => ({
export const withBorders = () => ({
components: { SRadio, SRow },
template: `
-
- {{ item.title }}
-
- `,
+
+ {{ item.title }}
+
+ `,
data: () => ({
model: 'first',
items: radioData
})
})
+
+export const radioButtonGroup = () => ({
+ components: { SRadio, SRadioGroup, SRow },
+ template: `
+
+
+ {{ item.title }}
+
+
+
+ v-model="{{ model }}"
+
+ `,
+ data: () => ({
+ model: 'first',
+ items: radioData
+ }),
+ props: {
+ size: {
+ default: select('Size', Object.values(RadioSize), RadioSize.MEDIUM)
+ },
+ disabled: {
+ default: boolean('Disabled', false)
+ }
+ }
+})
diff --git a/src/stories/SSlider.stories.ts b/src/stories/SSlider.stories.ts
index 5f2f76da..57dd9b62 100644
--- a/src/stories/SSlider.stories.ts
+++ b/src/stories/SSlider.stories.ts
@@ -1,13 +1,6 @@
import { text, number, boolean, select, object, withKnobs } from '@storybook/addon-knobs'
-import { SSlider } from '../components/Slider'
-
-enum InputSize {
- LARGE = 'large',
- MEDIUM = 'medium',
- SMALL = 'small',
- MINI = 'mini'
-}
+import { SSlider, SliderInputSize } from '../components/Slider'
export default {
component: SSlider,
@@ -122,7 +115,7 @@ export const withInput = () => ({
default: boolean('Show Input Controls', true)
},
inputSize: {
- default: select('Size of the input box', Object.values(InputSize), InputSize.SMALL)
+ default: select('Size of the input box', Object.values(SliderInputSize), SliderInputSize.SMALL)
},
debounce: {
default: number('Debounce delay when typing (in milliseconds)', 300)
diff --git a/src/stories/SSwitch.stories.ts b/src/stories/SSwitch.stories.ts
index 7ad0ef19..62c76629 100644
--- a/src/stories/SSwitch.stories.ts
+++ b/src/stories/SSwitch.stories.ts
@@ -1,4 +1,4 @@
-import { color, text, number, boolean, withKnobs } from '@storybook/addon-knobs'
+import { text, number, boolean, withKnobs } from '@storybook/addon-knobs'
import { SSwitch } from '../components/Switch'
@@ -14,8 +14,6 @@ export const configurable = () => ({
template: `
({
changeValue: true
}),
props: {
- activeColor: {
- default: color('Active Background Color', 'rgb(208, 2, 27)')
- },
- inactiveColor: {
- default: color('Inactive Background Color', 'rgb(246, 204, 209)')
- },
activeText: {
default: text('Active Text', '')
},
diff --git a/src/styles/radio.scss b/src/styles/radio.scss
index f7a0079d..8b92601b 100644
--- a/src/styles/radio.scss
+++ b/src/styles/radio.scss
@@ -1,6 +1,29 @@
@import "./variables";
@import "./common";
+$radio-button-class: ".el-radio-button";
+$radio-button-border-width: 1px;
+$radio-button-border-color: var(--s-color-main-brand);
+
+@mixin radio-button-size(
+ $modifier: "small",
+ $size: $s-size-small,
+ $font-size: $s-font-size-small
+) {
+ $radio-button-vertical-padding: #{($size - $font-size) / 2 - $radio-button-border-width};
+ #{$radio-button-class} {
+ &--#{$modifier} {
+ height: $size;
+ line-height: $size;
+ #{$radio-button-class}__inner {
+ padding-top: $radio-button-vertical-padding;
+ padding-bottom: $radio-button-vertical-padding;
+ font-size: $font-size;
+ }
+ }
+ }
+}
+
.el-radio {
color: var(--s-color-basic-black);
&.s-big {
@@ -98,4 +121,91 @@
}
}
}
+ &-button {
+ &:hover {
+ #{$radio-button-class}__inner {
+ border-color: $radio-button-border-color;
+ color: var(--s-color-main-brand);
+ }
+ &:not(:first-child):not(.is-disabled) {
+ #{$radio-button-class}__inner {
+ &:before {
+ opacity: 1;
+ }
+ }
+ }
+ }
+ &:not(:first-child):not(.is-disabled) {
+ #{$radio-button-class}__inner {
+ position: relative;
+ &:before {
+ content: "";
+ position: absolute;
+ display: block;
+ opacity: 0;
+ background-color: $radio-button-border-color;
+ height: calc(100% + #{$radio-button-border-width * 2});
+ width: $radio-button-border-width;
+ left: -#{$radio-button-border-width};
+ top: -#{$radio-button-border-width};
+ transition: inherit;
+ transition-property: opacity;
+ }
+ }
+ }
+ &.is-disabled {
+ #{$radio-button-class}__inner {
+ color: var(--s-color-neutral-inactive);
+ }
+ }
+ &.is-disabled,
+ &.is-disabled:hover {
+ #{$radio-button-class}__inner {
+ border-color: var(--s-color-neutral-border);
+ }
+ }
+ &.is-active {
+ &:hover {
+ #{$radio-button-class}__inner {
+ background-color: var(--s-color-main-hover);
+ border-color: var(--s-color-main-hover);
+ }
+ }
+ &.is-disabled {
+ #{$radio-button-class}__inner {
+ color: var(--s-color-basic-white);
+ }
+ }
+ &.is-disabled,
+ &.is-disabled:hover {
+ #{$radio-button-class}__inner {
+ background-color: var(--s-color-main-inactive);
+ border-color: var(--s-color-main-inactive);
+ }
+ }
+ }
+ }
+ &-group {
+ @include radio-button-size;
+ @include radio-button-size("medium", $s-size-medium, $s-font-size-big);
+ @include radio-button-size("big", $s-size-big, $s-font-size-big);
+ #{$radio-button-class} {
+ &__inner {
+ background-color: var(--s-color-basic-white);
+ border-color: var(--s-color-neutral-border);
+ color: var(--s-color-basic-black);
+ }
+ #{$radio-button-class}__inner {
+ box-shadow: none;
+ }
+ }
+ .is-disabled #{$radio-button-class}__inner {
+ background-color: var(--s-color-basic-white);
+ }
+ .is-active #{$radio-button-class}__inner {
+ background-color: var(--s-color-main-brand);
+ border-color: var(--s-color-main-brand);
+ color: var(--s-color-basic-white);
+ }
+ }
}
diff --git a/src/styles/slider.scss b/src/styles/slider.scss
index 0c35fafb..7940b83e 100644
--- a/src/styles/slider.scss
+++ b/src/styles/slider.scss
@@ -35,6 +35,9 @@
&__marks-text {
color: var(--s-color-basic-black);
}
+ &__bar {
+ background-color: var(--s-color-main-brand);
+ }
}
.disabled {
.el-slider__bar {
@@ -93,5 +96,5 @@
@include slider-input-size;
@include slider-input-size("small", $s-size-small);
@include slider-input-size("medium", $s-size-medium);
- @include slider-input-size("large", $s-size-big);
+ @include slider-input-size("big", $s-size-big);
}
diff --git a/src/styles/switch.scss b/src/styles/switch.scss
index 7db1a641..ef8f32d1 100644
--- a/src/styles/switch.scss
+++ b/src/styles/switch.scss
@@ -1,10 +1,47 @@
@import "./variables";
+$switch-class: ".el-switch";
+
.s-switch {
- .el-switch__label {
- color: var(--s-color-basic-black);
- &.is-active {
- color: var(--s-color-main-brand);
+ #{$switch-class} {
+ &__label {
+ color: var(--s-color-basic-black);
+ &.is-active {
+ color: var(--s-color-main-brand);
+ }
+ }
+ &__core {
+ border-color: var(--s-color-neutral-border);
+ background-color: var(--s-color-neutral-border);
+ &:after {
+ background-color: var(--s-color-basic-white);
+ }
+ }
+ &:hover,
+ &.is-checked:hover {
+ #{$switch-class}__core {
+ background-color: var(--s-color-main-hover);
+ border-color: var(--s-color-main-hover);
+ }
+ }
+ &.is-disabled {
+ opacity: 1;
+ #{$switch-class}__core {
+ background-color: var(--s-color-neutral-placeholder);
+ border-color: var(--s-color-neutral-placeholder);
+ }
+ }
+ &.is-checked {
+ #{$switch-class}__core {
+ background-color: var(--s-color-main-brand);
+ border-color: var(--s-color-main-brand);
+ }
+ &.is-disabled {
+ #{$switch-class}__core {
+ background-color: var(--s-color-main-inactive);
+ border-color: var(--s-color-main-inactive);
+ }
+ }
}
}
}
diff --git a/src/styles/variables.scss b/src/styles/variables.scss
index 5b8ccd38..4d403700 100644
--- a/src/styles/variables.scss
+++ b/src/styles/variables.scss
@@ -27,6 +27,10 @@ $s-border-radius-default: 4px !default;
// Fonts
$font-family-default: 'Sora', sans-serif !important;
$font-family-mono: 'JetBrainsMono', monospace !important;
+// Font sizes
+$s-font-size-big: 14px !default;
+$s-font-size-small: 12px !default;
+
// Responsive
$--sm: 640px !default;
$--md: 1024px !default;
diff --git a/src/types/components.ts b/src/types/components.ts
index 040e6aa0..2f3923f9 100644
--- a/src/types/components.ts
+++ b/src/types/components.ts
@@ -31,6 +31,7 @@ export enum Components {
SOptionGroup = 'SOptionGroup',
SPagination = 'SPagination',
SRadio = 'SRadio',
+ SRadioGroup = 'SRadioGroup',
SRow = 'SRow',
SScrollSectionItem = 'SScrollSectionItem',
SScrollSections = 'SScrollSections',