ember-safe-button 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/addon-main.cjs +6 -0
- package/dist/_app_/components/safe-button/animations/flip.js +1 -0
- package/dist/_app_/components/safe-button/animations/index.js +1 -0
- package/dist/_app_/components/safe-button/animations/lift-bars.js +1 -0
- package/dist/_app_/components/safe-button/animations/poing.js +1 -0
- package/dist/_app_/components/safe-button/animations/roll.js +1 -0
- package/dist/_app_/components/safe-button/animations/slide.js +1 -0
- package/dist/_app_/components/safe-button/animations/zoom.js +1 -0
- package/dist/_app_/components/safe-button/index.js +1 -0
- package/dist/_app_/components/safety/index.js +1 -0
- package/dist/_app_/components/trigger/index.js +1 -0
- package/dist/_app_/modifiers/animate-me.js +1 -0
- package/dist/components/safe-button/animations/flip.js +103 -0
- package/dist/components/safe-button/animations/flip.js.map +1 -0
- package/dist/components/safe-button/animations/index.js +18 -0
- package/dist/components/safe-button/animations/index.js.map +1 -0
- package/dist/components/safe-button/animations/lift-bars.js +53 -0
- package/dist/components/safe-button/animations/lift-bars.js.map +1 -0
- package/dist/components/safe-button/animations/poing.js +93 -0
- package/dist/components/safe-button/animations/poing.js.map +1 -0
- package/dist/components/safe-button/animations/roll.js +57 -0
- package/dist/components/safe-button/animations/roll.js.map +1 -0
- package/dist/components/safe-button/animations/slide.js +57 -0
- package/dist/components/safe-button/animations/slide.js.map +1 -0
- package/dist/components/safe-button/animations/zoom.js +73 -0
- package/dist/components/safe-button/animations/zoom.js.map +1 -0
- package/dist/components/safe-button/index.js +9 -0
- package/dist/components/safe-button/index.js.map +1 -0
- package/dist/components/safety/index.js +54 -0
- package/dist/components/safety/index.js.map +1 -0
- package/dist/components/trigger/index.js +44 -0
- package/dist/components/trigger/index.js.map +1 -0
- package/dist/index-65a73164.js +249 -0
- package/dist/index-65a73164.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/modifiers/animate-me.js +23 -0
- package/dist/modifiers/animate-me.js.map +1 -0
- package/package.json +70 -69
- package/.gitlab-ci.yml +0 -27
- package/.prettierignore +0 -21
- package/.prettierrc.js +0 -5
- package/.vscode/settings.json +0 -19
- package/CHANGELOG.md +0 -126
- package/LICENSE.md +0 -9
- package/addon/components/safe-button/animations/flip.js +0 -114
- package/addon/components/safe-button/animations/index.js +0 -15
- package/addon/components/safe-button/animations/lift-bars.js +0 -50
- package/addon/components/safe-button/animations/poing.js +0 -99
- package/addon/components/safe-button/animations/roll.js +0 -50
- package/addon/components/safe-button/animations/slide.js +0 -50
- package/addon/components/safe-button/animations/zoom.js +0 -52
- package/addon/components/safe-button/index.hbs +0 -35
- package/addon/components/safe-button/index.js +0 -184
- package/addon/components/safety/index.hbs +0 -20
- package/addon/components/safety/index.js +0 -41
- package/addon/components/trigger/index.hbs +0 -20
- package/addon/components/trigger/index.js +0 -31
- package/addon/modifiers/animate-me.js +0 -20
- package/app/components/safe-button.js +0 -1
- package/app/components/safety.js +0 -1
- package/app/components/trigger.js +0 -2
- package/app/modifiers/animate-me.js +0 -1
- package/app/templates/components/safe-button.js +0 -1
- package/app/templates/components/safety.js +0 -1
- package/app/templates/components/trigger.js +0 -1
- package/config/addon-docs.js +0 -13
- package/config/deploy.js +0 -29
- package/config/environment.js +0 -5
- package/config/tailwindcss-config.js +0 -924
- package/doc/demo.gif +0 -0
- package/doc/logo.png +0 -0
- package/index.js +0 -5
- package/netlify.toml +0 -3
- package/renovate.json +0 -75
- package/yarn-error.log +0 -13431
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { timeout } from 'ember-concurrency';
|
|
3
|
-
import { tracked } from '@glimmer/tracking';
|
|
4
|
-
import { task } from 'ember-concurrency';
|
|
5
|
-
import { action } from '@ember/object';
|
|
6
|
-
import embeddedAnimations from './animations';
|
|
7
|
-
import { assert } from '@ember/debug';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_TIMEOUT = 3000;
|
|
10
|
-
const DEFAULT_ANIMATION = 'slide';
|
|
11
|
-
|
|
12
|
-
export const SAFETY_STATUS = {
|
|
13
|
-
LOCKED: 1,
|
|
14
|
-
UNLOCKING: 2,
|
|
15
|
-
UNLOCKED: 3,
|
|
16
|
-
LOCKING: 4,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
Main component.
|
|
21
|
-
|
|
22
|
-
```hbs
|
|
23
|
-
<SafeButton
|
|
24
|
-
class="border-black"
|
|
25
|
-
@animation={{this.animation}}
|
|
26
|
-
@message="Delete me"
|
|
27
|
-
@timeout={{2000}}
|
|
28
|
-
@onConfirm={{action safeButtonClicked}} />
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
@class SafeButtonComponent
|
|
33
|
-
@param {string} [class="ember-safe-button"] CSS class to be applied on the wrapping element.
|
|
34
|
-
@param {object} [animation="slid"] Definition of animation; It can either be string and point to one of the pre-defined animations; Or it can be an object describing Web Animation API
|
|
35
|
-
@param {number} [timeout=3000] Number of millisenconds after which the safety rolls back over the trigger.
|
|
36
|
-
@param {string} [message="delete"] Text to be printed on the buttons in case block is not provided.
|
|
37
|
-
@param {function} onConfirm - Action to trigger whenever user clicks the trigger.
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
When trying to construct your own `@animation` object you can take inspiration from the simple `slide` animation. The thing to keep in mind is that these go directly as parameters to [element.animate()](https://developer.mozilla.org/en-US/docs/Web/API/Element/animate) and that there are in fact four animations of which always two fire at the same time:
|
|
41
|
-
|
|
42
|
-
- `safety.unlocking` and `trigger.unlocking`
|
|
43
|
-
- `safety.locking` and `trigger.locking`
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
{
|
|
47
|
-
safety: {
|
|
48
|
-
unlocking: {
|
|
49
|
-
keyframes: [
|
|
50
|
-
{ transform: 'translateX(0)' },
|
|
51
|
-
{ transform: 'translateX(-100%)' },
|
|
52
|
-
],
|
|
53
|
-
options: {
|
|
54
|
-
duration: 1000,
|
|
55
|
-
fill: 'both',
|
|
56
|
-
easing: 'ease',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
locking: {
|
|
60
|
-
keyframes: [
|
|
61
|
-
{ transform: 'translateX(-100%)' },
|
|
62
|
-
{ transform: 'translateX(0)' },
|
|
63
|
-
],
|
|
64
|
-
options: {
|
|
65
|
-
duration: 1000,
|
|
66
|
-
fill: 'both',
|
|
67
|
-
easing: 'ease',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
trigger: {
|
|
72
|
-
unlocking: {
|
|
73
|
-
keyframes: [
|
|
74
|
-
{ transform: 'translateX(100%)' },
|
|
75
|
-
{ transform: 'translateX(0)' },
|
|
76
|
-
],
|
|
77
|
-
options: {
|
|
78
|
-
duration: 1000,
|
|
79
|
-
fill: 'both',
|
|
80
|
-
easing: 'ease',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
locking: {
|
|
84
|
-
keyframes: [
|
|
85
|
-
{ transform: 'translateX(0)' },
|
|
86
|
-
{ transform: 'translateX(100%)' },
|
|
87
|
-
],
|
|
88
|
-
options: {
|
|
89
|
-
duration: 1000,
|
|
90
|
-
fill: 'both',
|
|
91
|
-
easing: 'ease',
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
*/
|
|
98
|
-
export default class SafeButtonComponent extends Component {
|
|
99
|
-
constructor() {
|
|
100
|
-
super(...arguments);
|
|
101
|
-
|
|
102
|
-
assert(
|
|
103
|
-
'@onConfirm attribute must be set',
|
|
104
|
-
typeof this.args.onConfirm === 'function'
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@tracked safetyStatus = SAFETY_STATUS.LOCKED;
|
|
109
|
-
|
|
110
|
-
get activeAnimation() {
|
|
111
|
-
const animation = this.args.animation || DEFAULT_ANIMATION;
|
|
112
|
-
|
|
113
|
-
return typeof animation === 'string'
|
|
114
|
-
? embeddedAnimations[animation]
|
|
115
|
-
: animation;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get webAnimations() {
|
|
119
|
-
const { activeAnimation, onUnlocked, onLocked } = this;
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
safety: {
|
|
123
|
-
unlocking: ({ element }) => {
|
|
124
|
-
let animation = element.animate(
|
|
125
|
-
activeAnimation.safety.unlocking.keyframes,
|
|
126
|
-
activeAnimation.safety.unlocking.options
|
|
127
|
-
);
|
|
128
|
-
animation.onfinish = onUnlocked;
|
|
129
|
-
},
|
|
130
|
-
locking: ({ element }) => {
|
|
131
|
-
let animation = element.animate(
|
|
132
|
-
activeAnimation.safety.locking.keyframes,
|
|
133
|
-
activeAnimation.safety.locking.options
|
|
134
|
-
);
|
|
135
|
-
animation.onfinish = onLocked;
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
trigger: {
|
|
139
|
-
unlocking({ element }) {
|
|
140
|
-
element.animate(
|
|
141
|
-
activeAnimation.trigger.unlocking.keyframes,
|
|
142
|
-
activeAnimation.trigger.unlocking.options
|
|
143
|
-
);
|
|
144
|
-
},
|
|
145
|
-
locking({ element }) {
|
|
146
|
-
element.animate(
|
|
147
|
-
activeAnimation.trigger.locking.keyframes,
|
|
148
|
-
activeAnimation.trigger.locking.options
|
|
149
|
-
);
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
get timeout() {
|
|
156
|
-
return this.args.timeout || DEFAULT_TIMEOUT;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get displayedMessage() {
|
|
160
|
-
return this.args.message || 'delete';
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
@action
|
|
164
|
-
onUnlocking() {
|
|
165
|
-
this.safetyStatus = SAFETY_STATUS.UNLOCKING;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
@action
|
|
169
|
-
onUnlocked() {
|
|
170
|
-
this.safetyStatus = SAFETY_STATUS.UNLOCKED;
|
|
171
|
-
this.triggerSafety.perform();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
@action
|
|
175
|
-
onLocked() {
|
|
176
|
-
this.safetyStatus = SAFETY_STATUS.LOCKED;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
@task(function* () {
|
|
180
|
-
yield timeout(this.timeout);
|
|
181
|
-
this.safetyStatus = SAFETY_STATUS.LOCKING;
|
|
182
|
-
})
|
|
183
|
-
triggerSafety;
|
|
184
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<button
|
|
2
|
-
class={{this.BASIC_CLASS}}
|
|
3
|
-
disabled={{this.isDisabled}}
|
|
4
|
-
aria-label={{this.ariaLabel}}
|
|
5
|
-
type='button'
|
|
6
|
-
tabindex={{if this.isDisabled '-1' '0'}}
|
|
7
|
-
...attributes
|
|
8
|
-
{{on 'click' @onClick}}
|
|
9
|
-
{{animate-me
|
|
10
|
-
safetyStatus=@safetyStatus
|
|
11
|
-
webAnimations=@webAnimations
|
|
12
|
-
focusMe=this.focusMe
|
|
13
|
-
}}
|
|
14
|
-
>
|
|
15
|
-
{{#if (has-block)}}
|
|
16
|
-
{{yield}}
|
|
17
|
-
{{else}}
|
|
18
|
-
{{@displayedMessage}}
|
|
19
|
-
{{/if}}
|
|
20
|
-
</button>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { SAFETY_STATUS } from '../safe-button';
|
|
3
|
-
|
|
4
|
-
export const BASIC_CLASS = 'ember-safe-button-safety';
|
|
5
|
-
export const ARIA_LABELS = {
|
|
6
|
-
[SAFETY_STATUS.LOCKED]: 'Deactivate safety',
|
|
7
|
-
[SAFETY_STATUS.UNLOCKING]: 'Deactivating safety',
|
|
8
|
-
[SAFETY_STATUS.UNLOCKED]: 'Safety not active',
|
|
9
|
-
[SAFETY_STATUS.LOCKING]: 'Activating safety',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
Safety is a component that covers the trigger.
|
|
14
|
-
|
|
15
|
-
```hbs
|
|
16
|
-
<SafeButton
|
|
17
|
-
@onConfirm={{action safeButtonClicked}} as |button|
|
|
18
|
-
>
|
|
19
|
-
<button.safety class="bg-grey-light">
|
|
20
|
-
This is safety
|
|
21
|
-
</button.safety>
|
|
22
|
-
</SafeButton>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
@class SafetyComponent
|
|
26
|
-
*/
|
|
27
|
-
export default class SafetyComponent extends Component {
|
|
28
|
-
BASIC_CLASS = BASIC_CLASS;
|
|
29
|
-
|
|
30
|
-
get isDisabled() {
|
|
31
|
-
return this.args.safetyStatus === SAFETY_STATUS.UNLOCKED;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get focusMe() {
|
|
35
|
-
return !this.isDisabled;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get ariaLabel() {
|
|
39
|
-
return ARIA_LABELS[this.args.safetyStatus];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<button
|
|
2
|
-
class={{this.BASIC_CLASS}}
|
|
3
|
-
disabled={{this.isDisabled}}
|
|
4
|
-
aria-label='Confirm action'
|
|
5
|
-
type='button'
|
|
6
|
-
tabindex={{if this.isDisabled '-1' '0'}}
|
|
7
|
-
...attributes
|
|
8
|
-
{{on 'click' @onClick}}
|
|
9
|
-
{{animate-me
|
|
10
|
-
safetyStatus=@safetyStatus
|
|
11
|
-
webAnimations=@webAnimations
|
|
12
|
-
focusMe=this.focusMe
|
|
13
|
-
}}
|
|
14
|
-
>
|
|
15
|
-
{{#if (has-block)}}
|
|
16
|
-
{{yield}}
|
|
17
|
-
{{else}}
|
|
18
|
-
{{@displayedMessage}}
|
|
19
|
-
{{/if}}
|
|
20
|
-
</button>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { SAFETY_STATUS } from '../safe-button';
|
|
3
|
-
|
|
4
|
-
export const BASIC_CLASS = 'ember-safe-button-trigger';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
Trigger is a component that is by default covered by safety and triggers the action passed to <SafeButton> when clicked.
|
|
8
|
-
|
|
9
|
-
```hbs
|
|
10
|
-
<SafeButton
|
|
11
|
-
@onConfirm={{action safeButtonClicked}} as |button|
|
|
12
|
-
>
|
|
13
|
-
<button.trigger class="bg-red-dark">
|
|
14
|
-
Trigger
|
|
15
|
-
</button.trigger>
|
|
16
|
-
</SafeButton>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
@class SafetyComponent
|
|
20
|
-
*/
|
|
21
|
-
export default class TriggerComponent extends Component {
|
|
22
|
-
BASIC_CLASS = BASIC_CLASS;
|
|
23
|
-
|
|
24
|
-
get isDisabled() {
|
|
25
|
-
return this.args.safetyStatus !== SAFETY_STATUS.UNLOCKED;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get focusMe() {
|
|
29
|
-
return !this.isDisabled;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Modifier from 'ember-modifier';
|
|
2
|
-
import { SAFETY_STATUS } from '../components/safe-button';
|
|
3
|
-
|
|
4
|
-
export default class AnimateMeModifier extends Modifier {
|
|
5
|
-
didReceiveArguments() {
|
|
6
|
-
if (this.args.named.focusMe) {
|
|
7
|
-
this.element.focus();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (this.args.named.safetyStatus === SAFETY_STATUS.UNLOCKING) {
|
|
11
|
-
this.args.named.webAnimations.unlocking({
|
|
12
|
-
element: this.element,
|
|
13
|
-
});
|
|
14
|
-
} else if (this.args.named.safetyStatus === SAFETY_STATUS.LOCKING) {
|
|
15
|
-
this.args.named.webAnimations.locking({
|
|
16
|
-
element: this.element,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-safe-button/components/safe-button';
|
package/app/components/safety.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-safe-button/components/safety';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-safe-button/modifiers/animate-me';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-safe-button/templates/components/safe-button';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-safe-button/templates/components/safety';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-safe-button/templates/components/trigger';
|
package/config/addon-docs.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* eslint-disable node/no-unpublished-require */
|
|
2
|
-
/* eslint-disable unicorn/prevent-abbreviations */
|
|
3
|
-
/* eslint-env node */
|
|
4
|
-
'use strict';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line node/no-unpublished-require
|
|
7
|
-
// eslint-disable-next-line node/no-missing-require
|
|
8
|
-
const AddonDocsConfig = require('ember-cli-addon-docs/lib/config');
|
|
9
|
-
|
|
10
|
-
module.exports = class extends AddonDocsConfig {
|
|
11
|
-
// See https://ember-learn.github.io/ember-cli-addon-docs/docs/deploying
|
|
12
|
-
// for details on configuration you can override here.
|
|
13
|
-
};
|
package/config/deploy.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
module.exports = function (deployTarget) {
|
|
5
|
-
let ENV = {
|
|
6
|
-
build: {},
|
|
7
|
-
// include other plugin configuration that applies to all deploy targets here
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
if (deployTarget === 'development') {
|
|
11
|
-
ENV.build.environment = 'development';
|
|
12
|
-
// configure other plugins for development deploy target here
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (deployTarget === 'staging') {
|
|
16
|
-
ENV.build.environment = 'production';
|
|
17
|
-
// configure other plugins for staging deploy target here
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (deployTarget === 'production') {
|
|
21
|
-
ENV.build.environment = 'production';
|
|
22
|
-
// configure other plugins for production deploy target here
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Note: if you need to build some configuration asynchronously, you can return
|
|
26
|
-
// a promise that resolves with the ENV object instead of returning the
|
|
27
|
-
// ENV object synchronously.
|
|
28
|
-
return ENV;
|
|
29
|
-
};
|