Skip to content

Commit 2003c60

Browse files
committed
feat: ArrowDraw, a handdrawn arrow svg
This is a handdrawn arrow in svg. It can be colored. This add a new metho to layoutHelper.ts which can look up the hex code for certain tailwind like colors like red-400.
1 parent 8f5a966 commit 2003c60

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

components/ArrowDraw.vue

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script setup>
2+
import { computed } from 'vue'
3+
import { resolveColor } from '../layoutHelper'
4+
const props = defineProps({
5+
color: {
6+
type: String,
7+
default: '#000000',
8+
},
9+
width: {
10+
type: String,
11+
default: '140px', // Default width in pixels
12+
},
13+
})
14+
15+
const colorFill = computed(() => resolveColor(props.color))
16+
</script>
17+
18+
<template>
19+
<svg
20+
version="1.1"
21+
id="Layer_1"
22+
xmlns="http://www.w3.org/2000/svg"
23+
xmlns:xlink="http://www.w3.org/1999/xlink"
24+
x="0px"
25+
y="0px"
26+
viewBox="0 0 196 73"
27+
style="enable-background: new 0 0 196 73"
28+
xml:space="preserve"
29+
:width="width"
30+
>
31+
<path
32+
class="st0"
33+
d="M171.2,37.2c-12.8,0-25.6-0.9-38.3,0.2c-38.7,3.1-77.3,5.6-116.1,4.8c-2.5,0-5.1,0.4-7.5-0.1
34+
c-1.7-0.4-3.2-1.9-4.8-2.9c1.6-1.3,3.1-3.6,4.8-3.7c7-0.4,14-0.2,21-0.2c14.6,0,29.2,0.4,43.9,0c13.1-0.4,26.2-1.5,39.3-2.4
35+
c18.2-1.3,36.4-2.7,54.6-4c0.4,0,0.8-0.3,1.8-0.6c-5.6-5.8-12.3-8-19.5-9.4c-1.3-0.3-2.6-0.5-3.8-0.9c-3.5-1.1-5.7-3.4-4.5-7.1
36+
c1.2-3.7,4.6-3.7,7.5-2.5c7.4,2.9,14.8,5.9,22,9.2c4.4,2,8.6,4.4,12.7,6.9c4.6,2.8,5.1,6.7,0.9,10.1c-7.1,5.6-14.5,10.8-21.6,16.4
37+
c-5.2,4.1-9.9,8.7-15,12.8c-1.6,1.3-3.8,1.7-5.7,2.5c0-2.4-1-5.7,0.2-7c4.3-4.6,9.1-8.7,14-12.6C161.8,43.1,166.8,40.1,171.2,37.2z"
38+
/>
39+
</svg>
40+
</template>
41+
42+
<style scoped>
43+
.st0 {
44+
fill: v-bind(colorFill);
45+
}
46+
</style>

docs/.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default defineConfig({
6060
{ text: 'CreditScroll', link: '/components/creditscroll' },
6161
{ text: 'QRCode', link: '/components/qrcode' },
6262
{ text: 'Kawaii', link: '/components/kawaii' },
63+
{ text: 'ArrowDraw', link: '/components/arrowdraw' },
6364
{ text: 'ArrowHeads', link: '/components/arrowheads' },
6465
],
6566
},

docs/.vitepress/theme/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import StickyNote from '../../../components/StickyNote.vue'
1212
import QrcodeVue from 'qrcode.vue'
1313
import SpeechBubble from '../../../components/SpeechBubble.vue'
1414

15+
import ArrowDraw from '../../../components/ArrowDraw.vue'
1516
import BackPack from '../../../components/vue3-kawaii/components/backpack/BackPack.vue'
1617
import Browser from '../../../components/vue3-kawaii/components/browser/Browser.vue'
1718
import Cat from '../../../components/vue3-kawaii/components/cat/Cat.vue'
@@ -37,6 +38,7 @@ export default {
3738
app.component('StickyNote', StickyNote)
3839
app.component('QRCode', QrcodeVue)
3940
app.component('SpeechBubble', SpeechBubble)
41+
app.component('ArrowDraw', ArrowDraw)
4042
app.component('BackPack', BackPack)
4143
app.component('Browser', Browser)
4244
app.component('Cat', Cat)

docs/components.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The current components are:
1818

1919
- [Email](/components/email) - formats email addresses
2020

21+
- [ArrowDraw](/components/arrowdraw) - draws a hand-drawn looking arrow
22+
2123
- [ArrowHeads](/components/arrowheads) - draws a bunch of arrows pointing at a central place. Useful for drawing attention to a particular part of a slide.
2224

2325
Most component can just be included in-line in your markdown. However, in some cases it can make sense to position these components using the `v-drag` directive. For example, the `SpeechBubble` component can be positioned using the `v-drag` directive to place it in a specific location on the slide. This can be useful for creating custom layouts or animations. In that case, it makes sense to keep the component in the [default slot](/layouts#slots) of each layout.

layoutHelper.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
import type { CSSProperties } from 'vue'
2+
import { colors } from '@unocss/preset-mini'
3+
4+
export function resolveColor(colorName: string, defaultColor: string = '#000000'): string {
5+
// If the input is already a hex code, return it
6+
if (/^#([0-9A-F]{3}){1,2}$/i.test(colorName)) {
7+
return colorName
8+
}
9+
10+
// Split the color name into base and shade
11+
const [baseColor, shade] = colorName.toLowerCase().split('-')
12+
13+
// Function to find the color in the colors object
14+
function findColor(obj: any, base: string, shade?: string): string | null {
15+
if (base in obj) {
16+
if (shade && typeof obj[base] === 'object' && shade in obj[base]) {
17+
return obj[base][shade]
18+
} else if (!shade && typeof obj[base] === 'string') {
19+
return obj[base]
20+
}
21+
}
22+
23+
for (const value of Object.values(obj)) {
24+
if (typeof value === 'object' && value !== null) {
25+
const result = findColor(value, base, shade)
26+
if (result) return result
27+
}
28+
}
29+
30+
return null
31+
}
32+
33+
// Search for the color in the UnoCSS colors object
34+
const hexCode = findColor(colors, baseColor, shade)
35+
36+
// If a valid color is found, return its hex code; otherwise, return the default color
37+
return hexCode || defaultColor
38+
}
239

340
/**
441
* Resolve urls from frontmatter and append with the base url

0 commit comments

Comments
 (0)