Skip to content

Commit 7dcac09

Browse files
committed
feat: add <select> tag to FormField.vue
+ change form CSS styles + change <Button> style + add more fields to each example + toggling slide buttons after animation
1 parent dbae79a commit 7dcac09

File tree

5 files changed

+136
-43
lines changed

5 files changed

+136
-43
lines changed

docs/.vitepress/components/AnimationForm.vue

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,77 @@
3030
});
3131
const formRefFn = () => form;
3232
33-
const firstRow = [
33+
const allFields = [
3434
{ label: 'duration' },
3535
{ label: 'delay' },
3636
{ label: 'staggerDelay' },
3737
{ label: 'blur' },
38-
{ label: 'maintainSpace', type: 'checkbox' },
39-
{ label: 'transfOrigin' },
40-
];
41-
const secondRow = [
4238
{ label: 'easing' },
39+
{ label: 'maintainSpace', type: 'checkbox' },
4340
{
4441
label: 'dimensionsTransition',
4542
type: 'checkbox',
4643
},
44+
{
45+
label: 'transfOrigin',
46+
tagName: 'select',
47+
selectOptions: [
48+
{ text: 'center', selected: true },
49+
{ text: 'top' },
50+
{ text: 'bottom', selected: true },
51+
],
52+
},
4753
{ label: 'overflowHidden', type: 'checkbox' },
48-
{ label: 'iteration' },
49-
{ label: 'direction' },
50-
];
51-
const rowsList = [
52-
firstRow.filter(field => fieldsList?.indexOf(field.label) !== -1),
53-
secondRow.filter(field => fieldsList?.indexOf(field.label) !== -1),
54+
{
55+
label: 'iteration',
56+
tagName: 'select',
57+
selectOptions: [
58+
{ text: '1', selected: true },
59+
{ text: '2' },
60+
{ text: '3' },
61+
{ text: '4' },
62+
{ text: '5' },
63+
{ text: 'infinite' },
64+
],
65+
},
66+
{
67+
label: 'direction',
68+
tagName: 'select',
69+
selectOptions: [
70+
{ text: 'normal', selected: true },
71+
{ text: 'reverse' },
72+
{ text: 'alternate' },
73+
{ text: 'alternate-reverse' },
74+
],
75+
},
5476
];
5577
78+
const customFields = allFields.filter(
79+
field => fieldsList?.indexOf(field.label) !== -1
80+
);
81+
5682
defineEmits(['resetAnimation']);
5783
</script>
5884
5985
<template>
6086
<Container class="form--container">
6187
<div class="column">
62-
<div v-for="row in rowsList" class="row">
88+
<div class="row">
6389
<FormField
64-
v-for="field in row"
90+
v-for="field in customFields"
6591
:form="formRefFn"
6692
:label="field.label"
6793
:type="field.type"
94+
:tag-name="field.tagName"
95+
:select-options="field.selectOptions ?? []"
6896
@change-field="opts => $emit('resetAnimation', opts)"
6997
/>
7098
</div>
7199
</div>
72100
</Container>
73101
</template>
74102
75-
<style>
103+
<style scoped>
76104
.column {
77105
display: flex;
78106
flex-direction: column;
@@ -81,6 +109,7 @@
81109
82110
.row {
83111
display: flex;
112+
justify-content: center;
84113
align-items: flex-end;
85114
flex-wrap: wrap;
86115
gap: 1rem;

docs/.vitepress/components/Button.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818
<style scoped>
1919
button {
2020
font-weight: 500;
21-
border: 2px solid var(--vp-c-divider);
21+
border: 2px solid var(--vp-c-gray-dark-1);
2222
padding: 0.25em 1em;
2323
border-radius: 0.5rem;
2424
background-color: var(--vp-c-bg-soft);
2525
}
2626
27-
button:hover {
28-
border-color: var(--vp-c-brand);
29-
}
30-
3127
button:active,
32-
button:focus {
28+
button:focus,
29+
button:hover {
3330
border-color: var(--vp-c-brand);
3431
color: var(--vp-c-brand);
3532
}

docs/.vitepress/components/FormField.vue

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
66
const props = defineProps({
77
form: Function,
8-
initial: Object,
98
className: Function,
109
label: String,
1110
type: String,
1211
eventName: String,
12+
tagName: String,
13+
selectOptions: Array,
1314
});
14-
const { label = '', type = 'text', initial } = props;
15+
const {
16+
label = '',
17+
type = 'text',
18+
tagName = 'input',
19+
selectOptions = [],
20+
} = props;
1521
const form = typeof props.form === 'function' ? props.form() : ref({});
1622
1723
function toKebabCase(label) {
@@ -32,40 +38,78 @@
3238
>
3339
{{ label }}:
3440
<input
41+
v-if="tagName === 'input'"
3542
v-model="form[label]"
3643
@change="$emit('changeField', form)"
3744
:type="type"
3845
:id="toKebabCase(label)"
3946
:name="toKebabCase(label)"
4047
:disabled="label === 'dimensionsTransition' ? form.maintainSpace : false"
4148
/>
49+
<select
50+
v-if="tagName === 'select'"
51+
v-model="form[label]"
52+
@change="$emit('changeField', form)"
53+
:id="toKebabCase(label)"
54+
:name="toKebabCase(label)"
55+
>
56+
<option
57+
v-for="option in selectOptions"
58+
:selected="option.selected ?? false"
59+
>
60+
{{ option.text }}
61+
</option>
62+
</select>
4263
</label>
4364
</template>
4465

4566
<style scoped>
4667
input {
47-
border: 1px solid var(--vp-badge-info-border);
4868
margin: 0;
49-
width: 3rem;
69+
width: 4rem;
5070
}
5171
5272
#easing {
53-
width: 15rem;
73+
width: 15.5rem;
5474
}
5575
5676
#transf-origin {
5777
width: 5rem;
5878
}
5979
6080
input[type='checkbox'] {
81+
inset-inline: 2px solid var(--vp-c-green-darker);
6182
width: 1.5rem;
6283
}
6384
6485
input[type='checkbox']:disabled {
65-
border-color: var(--docsearch-muted-color);
86+
border-color: var(--docsearch-hit-color);
6687
}
6788
6889
.disabled {
6990
color: var(--vp-c-divider);
7091
}
92+
93+
select,
94+
input {
95+
appearance: listbox;
96+
-webkit-appearance: listbox;
97+
text-align: center;
98+
border: 1px solid var(--vp-c-gray-dark-1);
99+
border-radius: 4px;
100+
padding: 0.2em 0.6em;
101+
margin-top: 10px;
102+
background-color: var(--vp-c-bg);
103+
transition: background-color 0.5s;
104+
touch-action: manipulation;
105+
}
106+
107+
input:focus,
108+
select:focus {
109+
border: 1px solid var(--vp-c-green-lighter);
110+
}
111+
112+
select option {
113+
text-align: left;
114+
}
71115
</style>

docs/examples/examples.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,32 @@
33
"btnList": [
44
{
55
"text": [
6-
"Slide Up"
6+
"Slide Up",
7+
"Slide from Top"
78
],
89
"class": "slide-up--btn",
910
"targetSelector": ".example__slide"
1011
},
1112
{
1213
"text": [
13-
"Slide Down"
14+
"Slide Down",
15+
"Slide from Bottom"
1416
],
1517
"class": "slide-down--btn",
1618
"targetSelector": ".example__slide"
1719
},
1820
{
1921
"text": [
20-
"Slide Left"
22+
"Slide Left",
23+
"Slide from Left"
2124
],
2225
"class": "slide-left--btn",
2326
"targetSelector": ".example__slide"
2427
},
2528
{
2629
"text": [
27-
"Slide Right"
30+
"Slide Right",
31+
"Slide from Right"
2832
],
2933
"class": "slide-right--btn",
3034
"targetSelector": ".example__slide"

docs/examples/index.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,47 @@ aside: false
1111
import jsCssAnimations from '../../js-css-animations/js-css-animations.js';
1212
import '../../js-css-animations/js-animations.css';
1313

14+
function toggleBtnTitle(btnList, idx) {
15+
const btnSelector = btnList[idx].class;
16+
const btn = document.querySelector(`.${btnSelector}`)
17+
const btnText = btnList[idx].text;
18+
19+
btn.innerText = btn.innerText === btnText[0] ? btnText[1] : btnText[0];
20+
}
21+
1422
function slideAnimations() {
23+
const toggleSlideBtns = () => {
24+
toggleBtnTitle(examples.slide.btnList, 0);
25+
toggleBtnTitle(examples.slide.btnList, 1);
26+
toggleBtnTitle(examples.slide.btnList, 2);
27+
toggleBtnTitle(examples.slide.btnList, 3);
28+
}
1529
jsCssAnimations.init.slideUp({
1630
trigger: `.${ examples.slide.btnList[0].class }`,
31+
complete: () => {
32+
toggleSlideBtns();
33+
},
1734
});
1835
jsCssAnimations.init.slideDown({
1936
trigger: `.${ examples.slide.btnList[1].class }`,
37+
complete: () => {
38+
toggleSlideBtns();
39+
},
2040
});
2141
jsCssAnimations.init.slideLeft({
2242
trigger: `.${ examples.slide.btnList[2].class }`,
43+
complete: () => {
44+
toggleSlideBtns();
45+
},
2346
});
2447
jsCssAnimations.init.slideRight({
2548
trigger: `.${ examples.slide.btnList[3].class }`,
49+
complete: () => {
50+
toggleSlideBtns();
51+
},
2652
});
2753
}
2854

29-
function toggleBtnTitle(btnList, idx) {
30-
const btnSelector = btnList[idx].class;
31-
const btn = document.querySelector(`.${btnSelector}`)
32-
const btnText = btnList[idx].text;
33-
34-
btn.innerText = btn.innerText === btnText[0] ? btnText[1] : btnText[0];
35-
36-
}
37-
3855
const fadeOpts = {
3956
keepSpace: true,
4057
complete: () => {
@@ -62,22 +79,24 @@ aside: false
6279
const triggerSelector = `.${btn.class}`;
6380
jsCssAnimations.end(triggerSelector);
6481

65-
const default_value = {
82+
const defaultValue = {
6683
duration: '800ms',
6784
delay: '0ms',
6885
staggerDelay: '0ms',
6986
timingFunction: 'cubic-bezier(0.455, 0.03, 0.515, 0.955)',
87+
blur: '0.5px'
7088
}
7189

7290
const easingRegEx = /^(ease(-in|-out|-in-out)?|linear|cubic-bezier\((0|1|0.\d+), -?[\d\.]+, (0|1|0.\d+), -?[\d\.]+\)|step\((100|[0-9][0-9]|[0-9]),\s?(jump-start|jump-end|jump-none|jump-both|start|end)\)|step\(step-(start|end)\))$/;
7391

7492
if (opts.maintainSpace) opts.dimensionsTransition = false;
93+
if (!opts.blur.match(/^(\d+|\d+\.\d+)(px|rem|em)$/)) opts.blur = defaultValue.blur;
7594
if (!opts.easing || !opts.easing.match(easingRegEx))
76-
opts.easing = default_value.timingFunction;
95+
opts.easing = defaultValue.timingFunction;
7796
['duration', 'delay', 'staggerDelay'].forEach(prop => {
7897
if (opts[prop].match(/^\d+$/)) opts[prop] = `${opts[prop]}ms`;
7998
else if (!opts[prop].match(/^(\d+ms|\d+s)$/)) {
80-
opts[prop] = default_value[prop];
99+
opts[prop] = defaultValue[prop];
81100
}
82101
});
83102

@@ -105,7 +124,7 @@ aside: false
105124
:content-list="examples.slide.contentList"
106125
:anim-opts="{}"
107126
@reset-animation="(opts) => {resetAnimation('slide', opts);}"
108-
:fields-list="['duration', 'delay', 'staggerDelay', 'maintainSpace', 'easing', 'dimensionsTransition', 'overflowHidden', 'iteration']">
127+
:fields-list="['duration', 'delay', 'staggerDelay', 'maintainSpace', 'easing', 'dimensionsTransition', 'overflowHidden']">
109128

110129
```js{4}
111130
jsCssAnimations.init.slideUp({

0 commit comments

Comments
 (0)