Skip to content

Commit

Permalink
inline getIconVariable function
Browse files Browse the repository at this point in the history
Change-Id: Ib48d7a91a13ee8f093b025bca0b92f8992911c06
  • Loading branch information
BenediktSeidl committed Oct 22, 2024
1 parent f2dd0a3 commit d527119
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
19 changes: 18 additions & 1 deletion packages/cmk-frontend-vue/src/components/CmkIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@ conditions defined in the file COPYING, which is part of this source code packag
-->
<script setup lang="ts">
import { type VariantProps, cva } from 'class-variance-authority'
import { getIconVariable } from '@/lib/utils'

function getIconVariable(iconName: string | undefined): string {
/*
Transform from icon file name pattern
"icon_<underscored_name>.<file_extension>" or "<underscored_name>.<file_extension>"
to CSS variable name pattern, returned as a call to the CSS fct var()
"var(--icon-<dashed_name>)"

E.g. "icon_main_help.svg" -> "var(--icon-main-help)"
*/
if (!iconName) {
return 'none'
}

let iconVar: string = `${iconName.startsWith('icon') ? iconName : ['icon', iconName].join('-')}`
iconVar = iconVar.replace(/_/g, '-').split('.')[0]!
return `var(--${iconVar})`
}

const cmkIconVariants = cva('', {
variants: {
Expand Down
18 changes: 0 additions & 18 deletions packages/cmk-frontend-vue/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}

export function getIconVariable(iconName: string | undefined): string {
/*
Transform from icon file name pattern
"icon_<underscored_name>.<file_extension>" or "<underscored_name>.<file_extension>"
to CSS variable name pattern, returned as a call to the CSS fct var()
"var(--icon-<dashed_name>)"
E.g. "icon_main_help.svg" -> "var(--icon-main-help)"
*/
if (!iconName) {
return 'none'
}

let iconVar: string = `${iconName.startsWith('icon') ? iconName : ['icon', iconName].join('-')}`
iconVar = iconVar.replace(/_/g, '-').split('.')[0]!
return `var(--${iconVar})`
}

export const localStorageHandler = {
get: (key: string, defaultValue: unknown = null): unknown => {
const value = localStorage.getItem(key)
Expand Down

0 comments on commit d527119

Please sign in to comment.