Skip to content

Commit 6079647

Browse files
refactor: use style tag for color
Use the `style` tag instead of `stroke` and `fill` to define the color of the checkmark. BREAKING CHANGE: remove support for color classes Removes the support for color classes. Use the colors directly instead.
1 parent 9ef6cf9 commit 6079647

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

src/components/AnimatedCheckmark.vue

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,62 +26,45 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626
>
2727
<path
2828
class="success-animation-result"
29-
:class="colorClass"
30-
:fill="color"
29+
:style="style"
3130
d="M35,60 C21.1928813,60 10,48.8071187 10,35 C10,21.1928813 21.1928813,10 35,10 C48.8071187,10 60,21.1928813 60,35 C60,48.8071187 48.8071187,60 35,60 Z M23.6332378,33.2260427 L22.3667622,34.7739573 L34.1433655,44.40936 L47.776114,27.6305926 L46.223886,26.3694074 L33.8566345,41.59064 L23.6332378,33.2260427 Z"
3231
/>
3332
<circle
3433
class="success-animation-circle"
3534
cx="35"
3635
cy="35"
3736
r="24"
38-
:class="colorClass"
39-
:stroke="color"
37+
:style="style"
4038
stroke-width="2"
4139
stroke-linecap="round"
4240
/>
4341
<polyline
4442
class="success-animation-check"
45-
:class="colorClass"
46-
:stroke="color"
43+
:style="style"
4744
stroke-width="2"
4845
points="23 34 34 43 47 27"
4946
/>
5047
</svg>
5148
</template>
5249

5350
<script setup lang="ts">
51+
import { computed } from "vue";
52+
5453
/**
5554
* A checkmark animation wrapped in a Vue component based on a codepen by Simon Wuyts.
5655
*/
5756
const props = defineProps({
5857
/**
5958
* The color of the checkmark.
6059
*
61-
* Valid colors are:
62-
* - Available CSS-colors (for example: white, #000, etc.)
63-
* - Any custom CSS-class (a-zA-Z_-).
64-
*
65-
* If the color is an CSS-class, this class has to set the following properties:
66-
* - fill: [color]
67-
* - stroke: [color]
68-
*
69-
* If not set, it will be white.
60+
* Defaults to white.
7061
*/
7162
color: { type: String, default: "white" },
7263
});
7364
74-
/**
75-
* Returns the css-class to set for every svg-component.
76-
*
77-
* The class is the set {@link color}, if the regex /^[a-zA-Z_-]*$/ matches.
78-
*/
79-
function colorClass(): string {
80-
if (props.color && props.color.match(/^[a-zA-Z_-]*$/)) {
81-
return props.color;
82-
}
83-
return "";
84-
}
65+
const style = computed(() => {
66+
return `stroke: ${props.color}; fill: ${props.color};`;
67+
});
8568
</script>
8669

8770
<style lang="scss" scoped>

0 commit comments

Comments
 (0)