Lucide μμ΄μ½ ν©
- λ₯μ§
- Development
- λΆλ₯
- Javascript
- λ±λ‘μΌ
- 2024-05-05 03:15:49
- μ‘°νμ
- 424
- μ’μμ
- 0
κ½€ μ€λ«λμ μμ΄μ½ ν©λ€μ μ°Ύμν΄λ§€κ³ μμλ€.
κΈ°λ₯μ μ΄λ©΄ νλλ μ΄μμ§λ μμκ³ , μ΄μλ©΄ κΈ°λ₯μ μΌλ‘ λΆμ‘±νκΈ° λλ¬Έμ μ μ ν μλ¦λ€μκ³Ό κΈ°λ₯μ±μ κ°μΆ μμ΄μ½ μμ΄μ½ν©μ μ€λ«λμ λΉμ©μ λ€μ΄λ©΄μ μ°Ύμ ν΄λ§€κ³ μμλ€.
λ§μΉ¨λ΄ κ°μ₯ μ μ νκ²μ μ°Ύμλλ° Feather μμ΄μ½ν©μ΄λ©° μ¬νκΉμ§ μ¬μ©ν΄μ€κ³ μμλ€.
μ’
λ₯μμ νκ³λ₯Ό λλΌκΈ΄ νμ§λ§ λ€λ₯Έ λμμ΄ μμκΈ° λλ¬Έμ κ³μ μ¬μ©ν΄μ€κ³ μμλ€.
Feather μμ΄μ½μ νΉμ§μ μ·¨ν₯μ ν¬κ² νμ§μλμ κ³Ό μ μΌλ‘ λ§λ€μ΄μ Έ μμ΄μ κ΅΅κΈ°λ₯Ό μμ λ‘κ² λ³κ²½ κ°λ₯νλ€. μ λ³κ²½μ κΈ°λ³Έμ΄κ³ λ§μ΄λ€.
μ΅κ·Όμ Feather μμ΄μ½ λ² μ΄μ€λ‘ λ§λ€μ΄μ§ μ€νμμ€ μμ΄μ½ν© νλ‘μ νΈμΈ Lucideλ₯Ό μκ² λμλ€.
μ’ λ₯κ° λλ¨ν λ§κ³ , κΈ°μκ³Ό κ΄λ¦¬κ° λλ¨ν μλμ΄ μλ€λκ²μ λλλ€.
λ§μ ν₯λ―Έκ° μκΈ°κ³ κΌ μ¬μ©ν΄λ³΄μλ λ§μμ νμ¬ μ¬μ΄λ νλ‘μ νΈμμ μ¬μ©νκ³ μλ Feather μμ΄μ½ν©μμ κ΅μ²΄ν΄λ³΄κΈ°λ‘ νλ€.
μ μ©ν΄λ³΄κΈ°
μ΅κ·Όμ μ¬μ΄λλ‘ μ€νμμ€ νλ‘μ νΈλ₯Ό λ§λ€κ³ μλ λ°κ΅¬λμλ€ λ¨Όμ μ μ©ν΄λ³΄κ² λμλ€.
λ§μ μ¬μ©νλ €κ³ λ¬Έμλ€μ μ½μ΄λ³΄κ³ ν¨ν€μ§λ₯Ό μ€μΉν΄λ³΄κ³ μ μ©ν΄λ³΄λ νμμ μ νΈνλ λ°©μλλ‘ μ¬μ©νλκ²μ΄ μ½μ§ μμλ€.
κΈ°λ³Έμ μΌλ‘ μ¬μ©νλ λ°©μμ΄ μ»΄ν¬λνΈλ₯Ό importλ‘ μ§μ λΆλ¬μμ λ°λ‘ μ¬μ©νλ κ²μΈλ° μ¬λ¬κ°μ§ λΆνΈν¨κ³Ό μ μ°ν¨μ νκ³μ μ΄μ λ‘ μμ΄μ½μ κ°μΈλ λνΌ μ»΄ν¬λνΈλ₯Ό λ³λλ‘ λ§λ€μ΄ μ¬μ©νλ νΈμ΄λ€.
μμ΄μ½ ν©μ κ°―μκ° λλ¨ν λ§κΈ° λλ¬Έμ μ±λ₯μ λλ¨ν λ―Όκ°νκ² λλΌκΈ° λλ¬Έμ μ±λ₯μ μΌλ‘ λΆλ΄μλ μ νμ κΌ μ°μ ν΄μΌνλ μ΅μ μ΄λΌμ μ¬λ¬κ°μ§λ‘ κΉλ€λ‘λ€.
νμ¬κΉμ§ κ°μ₯ μ νΈνλ μ΅μ
μ λν μ»΄ν¬λνΈμμ <svg/>μ리먼νΈλ₯Ό κ°μΈκ³ μλ§Ήμ΄κ° λλ svg μ½λλ€μ μμ΄μ½μ μ§μ΄λ£λ λ°©μμ μ΄λ€. μ½λλ₯Ό μ§μ μ§μ΄λ£κΈ°λ νκ³ # λ§ν¬λ₯Ό κ±Έμ΄ μ°κ²°μν€κΈ°λ νλ€.
<svg xmlns="http://www.w3.org/2000/svg">
{ICON_CODE}
</svg>
μ΄λ° ꡬμ±μ κ³ μ§νλ μ΄μ λ μ€νμΌμ μ μ°ν¨ λλ¬Έμ΄λ€.
css varialbleλ‘ μμ΄μ½μ μ΅μ
μ μ»΄ν¬λνΈ propsλ₯Ό ν΅νμ§ μκ³ μ‘°μ ν μ μλ€.
κ²μΌλ‘ 보면 μ»΄ν¬λνΈ propsλ‘ μ¬μ΄μ¦λ μκ°μ μ€νμΌ κ°μ μ‘°μ νλκ²μ΄ νΈλ¦¬ν΄ 보μ΄μ§λ§ κ° μ‘°μ μ κ°μ₯ ν° νκ³λ css media queryλ€.
UIλΌλκ²μ λλ¨ν μ κΈ°μ μΈ μ₯λ₯΄λΌκ³ λ³Ό μ μλλ° cssμμ λ€μ΄ν°λΈνκ² λμν μ μλλ° μλ°μ€ν¬λ¦½νΈκΉμ§ μ¨κ°λ©° λμνλκ²μ κ΅μ₯ν μμ€λ§ λΆλ¬μΌμΌν¨λ€.
μ’ κ³ λ―Όμ νκ³ μ½μ§λμ λν μ»΄ν¬λνΈλ₯Ό λ§λ€κ² λμλ€.
vue λν μ»΄ν¬λνΈ
lucide νλ‘μ νΈμμ λ± μνλ ννλ‘ λ¦¬μμ€κ° μ 곡λμ΄μμ§ μμμ lucide νλ‘μ νΈμμ μ¬μ©νλ μμ€μ½λλ€μ λ―μ΄λ³΄λ©΄μ μνλ ννλ‘ κ°μ‘°ν΄λ³΄λ μλΉν μνλ ννλ‘ λμλ€.
<template>
<svg
v-if="icon"
v-html="icon"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
:class="[
'icon',
`icon--${props.name}`,
props.animation && `icon--animation-${props.animation}`,
]"
v-bind="wrapProps"/>
</template>
<script setup>
import { computed } from 'vue'
import { icons } from 'lucide'
const props = defineProps({
name: String,
color: String,
size: String,
stroke: Number,
animation: String,
animationSpeed: String,
})
const icon = computed(() => {
let src = icons[toPascalCase(props.name)]
if (!src) return null
const [ tag, attrs, children ] = src
const element = createSvgElement(tag, attrs, children)
return element.innerHTML
})
/**
* μΉ΄λ©μΌμ΄μ€ λ¬Έμλ‘ λ³κ²½
* @param {string} str
* @return {string}
*/
export function toPascalCase(str)
{
return str.replace(/(\w)(\w*)(_|-|\s*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase())
}
function createSvgElement(tag, attrs, children = [])
{
const element = document.createElementNS("http://www.w3.org/2000/svg", tag)
Object.keys(attrs).forEach((name) => {
element.setAttribute(name, String(attrs[name]))
})
if (children.length)
{
children.forEach((child) => {
const childElement = createSvgElement(...child)
element.appendChild(childElement)
})
}
return element
}
const wrapProps = computed(() => {
let attr = {
style: {},
}
if (props.color) attr.style['--icon-color'] = props.color
if (props.size) attr.style['--icon-size'] = props.size
if (props.stroke) attr.style['--icon-stroke'] = props.stroke
if (props.animationSpeed) attr.style['--icon-animation-speed'] = props.animationSpeed
return attr
})
</script>
<style lang="scss" scoped>
.icon {
display: block;
margin: var(--icon-margin, 0);
color: var(--icon-color, var(--color-base));
width: var(--icon-size, 24px);
height: var(--icon-size, 24px);
stroke-width: var(--icon-stroke, 2);
animation: var(--icon-animation, none);
transition: var(--icon-transition, none);
&--animation-rotate {
--icon-animation: spin var(--icon-animation-speed, 2000ms) linear infinite;
}
}
</style>
μΆμ²: https://github.com/redgoose-dev/baguni/blob/main/src/components/icons/index.vue
ꡬνμ ν΅μ¬μ createSvgElement() ν¨μμ μ€νμΌμνΈ λΆλΆλ€μΈλ° μλ Ήκ» λ³νμν¬ μ μλλ‘ μ°ΈννκΈ° μνμ¬ μ΄λ κ² λ
ΈνΈλ‘ κΈ°λ‘νλ κ²μ΄λ€.
μλ§λ svelte κ°μκ²λ μΌμΆ λΉμ·νκ² λ§λ€ μ μμκ²μ΄λ€.