-
Notifications
You must be signed in to change notification settings - Fork 2
Switch Component Addition #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c257e99
Added Switch Component.
alexnatalia 7e524fc
Switch Component: Added Story.
alexnatalia bbb254e
Switch Component: refactored, removed unnecessary fields from story.
alexnatalia 1346882
Merge branch 'develop' into feature/switch-component
alexnatalia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <template> | ||
| <div class="s-switch"> | ||
| <el-switch | ||
| ref="el-switch" | ||
| v-model="model" | ||
| :active-color="activeColor" | ||
| :inactive-color="inactiveColor" | ||
| :active-icon-class="activeIconСlass" | ||
| :inactive-icon-class="inactiveIconСlass" | ||
| :active-text="activeText" | ||
| :inactive-text="inactiveText" | ||
| :active-value="activeValue" | ||
| :inactive-value="inactiveValue" | ||
| :name="name" | ||
| :width="width" | ||
| :disabled="disabled" | ||
| @change="handleChange" | ||
| /> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { Vue, Component, Prop, Ref, Watch } from 'vue-property-decorator' | ||
| import { ElSwitch } from 'element-ui/types/switch' | ||
| @Component | ||
| export default class SSwitch extends Vue { | ||
| /** | ||
| * Value of switch | ||
| */ | ||
| @Prop({ default: false }) readonly value!: boolean | string | number | ||
| /** | ||
| * Background color when in on state | ||
| */ | ||
| @Prop({ default: '#d0021b', type: String }) readonly activeColor!: string | ||
| /** | ||
| * Background color when in off state | ||
| */ | ||
| @Prop({ default: '#f6ccd1', type: String }) readonly inactiveColor!: string | ||
| /** | ||
| * Class name of the icon displayed when in on state, overrides active-text | ||
| */ | ||
| @Prop({ default: '', type: String }) readonly activeIconСlass!: string | ||
| /** | ||
| * Class name of the icon displayed when in off state, overrides inactive-text | ||
| */ | ||
| @Prop({ default: '', type: String }) readonly inactiveIconСlass!: string | ||
| /** | ||
| * Text displayed when in on state | ||
| */ | ||
| @Prop({ default: '', type: String }) readonly activeText!: string | ||
| /** | ||
| * Text displayed when in off state | ||
| */ | ||
| @Prop({ default: '', type: String }) readonly inactiveText!: string | ||
| /** | ||
| * Switch value when in on state | ||
| */ | ||
| @Prop({ default: true }) readonly activeValue!: boolean | string | number | ||
| /** | ||
| * Switch value when in off state | ||
| */ | ||
| @Prop({ default: false }) readonly inactiveValue!: boolean | string | number | ||
| /** | ||
| * Input name of switch | ||
| */ | ||
| @Prop({ default: '', type: String }) readonly name!: string | ||
| /** | ||
| * Width of switch | ||
| */ | ||
| @Prop({ default: 40, type: Number }) readonly width!: number | ||
| /** | ||
| * Whether switch is disabled | ||
| */ | ||
| @Prop({ default: false, type: Boolean }) readonly disabled!: boolean | ||
| model = this.value | ||
| @Watch('value') | ||
| private handlePropChange (value: boolean | string | number): void { | ||
| this.model = value | ||
| } | ||
| @Watch('model') | ||
| private handleValueChange (value: boolean | string | number): void { | ||
| this.$emit('input', value) | ||
| } | ||
| handleChange (value: boolean | string | number): void { | ||
| this.$emit('change', value) | ||
| } | ||
| } | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import SSwitch from './SSwitch.vue' | ||
|
|
||
| export { SSwitch } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: `<div class="s-flex" style="flex: 1; flex-direction: column;"> | ||
| <s-switch | ||
| v-model="modelValue" | ||
| :active-color="activeColor" | ||
| :inactive-color="inactiveColor" | ||
| :active-text="activeText" | ||
| :inactive-text="inactiveText" | ||
| :active-value="activeValue" | ||
| :inactive-value="inactiveValue" | ||
| :width="width" | ||
| :disabled="disabled" | ||
| @change="(value) => changeValue = value" | ||
| /> | ||
| <span style="margin-top: 20px;"> | ||
| v-model="{{ modelValue }}", @change="{{ changeValue }}" | ||
| </span> | ||
| </div>`, | ||
| 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) | ||
| } | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.