-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
294 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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,99 @@ | ||
# Swap | ||
|
||
## Examples | ||
|
||
Swap text | ||
|
||
```html :::demo | ||
<div class="text-center"> | ||
<dv-swap on="ON" off="OFF" /> | ||
</div> | ||
``` | ||
|
||
Swap volume icons | ||
|
||
```tsx :::run | ||
export default { | ||
setup: () => { | ||
return () => ( | ||
<div class="text-center"> | ||
<dv-swap | ||
on={() => <dv-icon-volume-on size="48px" />} | ||
off={() => <dv-icon-volume-off size="48px" />} | ||
/> | ||
</div> | ||
); | ||
}, | ||
}; | ||
``` | ||
|
||
Swap icons with rotate effect | ||
|
||
```html :::demo | ||
<div class="text-center"> | ||
<dv-swap animation="rotate"> | ||
<template v-slot:on> | ||
<dv-icon-sun size="48px" /> | ||
</template> | ||
<template v-slot:off> | ||
<dv-icon-moon size="48px" /> | ||
</template> | ||
</dv-swap> | ||
</div> | ||
``` | ||
|
||
Swap with flip effect | ||
|
||
```tsx :::run | ||
export default { | ||
setup: () => { | ||
return () => ( | ||
<div class="text-center text-9xl"> | ||
<dv-swap on="😈" off="😇" animation="flip" /> | ||
</div> | ||
); | ||
}, | ||
}; | ||
``` | ||
|
||
Controlled swap | ||
|
||
```tsx :::run | ||
import { ref } from 'vue'; | ||
|
||
export default { | ||
setup: () => { | ||
const active = ref(false); | ||
return () => ( | ||
<div class="text-center"> | ||
<div class="py-2"> | ||
<dv-button onClick={() => (active.value = true)}>on</dv-button> | ||
/ | ||
<dv-button onClick={() => (active.value = false)}>off</dv-button> | ||
</div> | ||
<div class="text-9xl"> | ||
<dv-swap on="🥳" off="😭" animation="flip" active={active.value} /> | ||
</div> | ||
</div> | ||
); | ||
}, | ||
}; | ||
``` | ||
|
||
## Swap | ||
|
||
### Attributes | ||
|
||
| name | description | type | default | | ||
| --------- | ---------------- | ------------ | ------- | | ||
| on | render on | - | - | | ||
| off | render off | - | - | | ||
| tag | wrap elemnt tag | string | label | | ||
| animation | animation effect | rotate, flip | - | | ||
|
||
### Solts | ||
|
||
| name | description | | ||
| ---- | ----------- | | ||
| on | render on | | ||
| off | render off | |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,69 @@ | ||
import { componentV2 } from '@/shared/styled'; | ||
import { ExtractFromProps } from '@/shared/types/common'; | ||
import { getRenderResult, isUndefined } from '@/shared/utils'; | ||
import { computed, h, PropType, reactive } from 'vue'; | ||
import styles from './style'; | ||
|
||
const props = { | ||
on: { | ||
default: '', | ||
}, | ||
off: { | ||
default: '', | ||
}, | ||
tag: { | ||
type: String, | ||
default: 'label', | ||
}, | ||
active: { | ||
type: Boolean, | ||
default: void 0, | ||
}, | ||
animation: { | ||
type: String as PropType<'rotate' | 'flip'>, | ||
default: '', | ||
}, | ||
}; | ||
|
||
export type ISwapProps = ExtractFromProps<typeof props>; | ||
|
||
export const Swap = componentV2<ISwapProps>( | ||
{ | ||
name: 'Swap', | ||
props, | ||
setup: (props, { slots }) => { | ||
const state = reactive({ | ||
active: props.active, | ||
}); | ||
|
||
const finalActive = computed(() => | ||
isUndefined(props.active) ? state.active : props.active, | ||
); | ||
|
||
const cls = computed(() => [ | ||
'dv-swap swap', | ||
{ | ||
'swap-active': finalActive.value, | ||
[`swap-${props.animation}`]: props.animation, | ||
}, | ||
]); | ||
|
||
return () => { | ||
const on = getRenderResult('on', props, slots); | ||
const off = getRenderResult('off', props, slots); | ||
|
||
return h( | ||
props.tag, | ||
{ | ||
class: cls.value, | ||
onClick: () => { | ||
state.active = !state.active; | ||
}, | ||
}, | ||
[<div class="swap-on">{on}</div>, <div class="swap-off">{off}</div>], | ||
); | ||
}; | ||
}, | ||
}, | ||
styles, | ||
); |
This file contains 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 style from './style.less'; | ||
|
||
export default [style]; |
This file contains 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,69 @@ | ||
.dv-swap { | ||
@apply relative inline-grid select-none place-content-center; | ||
|
||
& > * { | ||
@apply col-start-1 row-start-1; | ||
} | ||
|
||
.swap-on { | ||
@apply opacity-0; | ||
} | ||
|
||
.swap-off { | ||
@apply opacity-100; | ||
} | ||
|
||
&.swap-active { | ||
.swap-on { | ||
@apply opacity-100; | ||
} | ||
.swap-off { | ||
@apply opacity-0; | ||
} | ||
} | ||
} | ||
|
||
.dv-swap { | ||
@apply cursor-pointer; | ||
|
||
& > * { | ||
@apply transition-all duration-300 ease-in-out; | ||
} | ||
} | ||
|
||
.swap-rotate { | ||
.swap-on { | ||
@apply rotate-45; | ||
} | ||
|
||
&.swap-active { | ||
.swap-on { | ||
@apply rotate-0; | ||
} | ||
.swap-off { | ||
@apply -rotate-45; | ||
} | ||
} | ||
} | ||
|
||
.swap-flip { | ||
transform-style: preserve-3d; | ||
perspective: 16em; | ||
|
||
.swap-on { | ||
transform: rotateY(180deg); | ||
backface-visibility: hidden; | ||
@apply opacity-100; | ||
} | ||
|
||
&.swap-active { | ||
.swap-on { | ||
transform: rotateY(0deg); | ||
} | ||
.swap-off { | ||
transform: rotateY(-180deg); | ||
backface-visibility: hidden; | ||
@apply opacity-100; | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.