Skip to content

Commit 83bd4e9

Browse files
committed
refactor(ui-icons-lucide): lucid icons to use new themes
1 parent f7dcd9f commit 83bd4e9

File tree

6 files changed

+52
-117
lines changed

6 files changed

+52
-117
lines changed

packages/ui-icons-lucide/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ import { wrapLucideIcon } from './wrapLucideIcon'
6363

6464
// Re-export types
6565
export type { LucideProps, LucideIcon } from 'lucide-react'
66-
export type {
67-
LucideIconWrapperProps,
68-
InstUIIconProps,
69-
LucideIconTheme
70-
} from './wrapLucideIcon'
66+
export type { LucideIconWrapperProps, InstUIIconProps } from './wrapLucideIcon'
7167

7268
// Re-export utilities
7369
export { wrapLucideIcon }

packages/ui-icons-lucide/src/wrapLucideIcon/index.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ import React, { forwardRef } from 'react'
2626
import type { LucideIcon } from 'lucide-react'
2727
import { useStyle, useTheme } from '@instructure/emotion'
2828
import { px } from '@instructure/ui-utils'
29+
import type { Theme } from '@instructure/ui-themes'
2930

3031
import generateStyle from './styles'
31-
import generateComponentTheme from './theme'
32-
import type {
33-
LucideIconWrapperProps,
34-
InstUIIconProps,
35-
LucideIconTheme
36-
} from './props'
32+
import type { LucideIconWrapperProps, InstUIIconProps } from './props'
3733

3834
/**
3935
* Wraps a Lucide icon component with InstUI theming and RTL support.
@@ -121,9 +117,9 @@ export function wrapLucideIcon(Icon: LucideIcon): LucideIcon {
121117
...rest
122118
} = props
123119

124-
// Get theme to convert semantic sizes to pixels
125-
const theme = useTheme()
126-
const componentTheme = generateComponentTheme(theme as any)
120+
// Get theme to access Icon component theme properties
121+
const theme = useTheme() as Theme
122+
const iconTheme = themeOverride || theme?.newTheme?.components?.Icon
127123

128124
// Determine if using InstUI semantic size or Lucide numeric size
129125
const isSemanticSize = typeof instUISize === 'string'
@@ -133,12 +129,14 @@ export function wrapLucideIcon(Icon: LucideIcon): LucideIcon {
133129
// Lucide doesn't inherit fontSize, so we need explicit pixel values
134130
let numericSize: number | undefined
135131
if (isSemanticSize) {
132+
// Map InstUI semantic sizes to Icon theme size properties
133+
// We map InstUI sizes to Icon theme sizes based on relative scale
136134
const sizeMap = {
137-
'x-small': componentTheme.sizeXSmall,
138-
small: componentTheme.sizeSmall,
139-
medium: componentTheme.sizeMedium,
140-
large: componentTheme.sizeLarge,
141-
'x-large': componentTheme.sizeXLarge
135+
'x-small': iconTheme?.sizeSm || '1rem', // sizeSm (16px)
136+
small: iconTheme?.sizeMd || '1.25rem', // sizeMd (20px)
137+
medium: iconTheme?.sizeLg || '1.5rem', // sizeLg (24px)
138+
large: iconTheme?.sizeXl || '2rem', // sizeXl (32px)
139+
'x-large': iconTheme?.size2xl || '2.25rem' // size2xl (36px)
142140
}
143141
const themeSizeValue = sizeMap[instUISize as keyof typeof sizeMap]
144142
// Use InstUI's px utility to convert rem/em to pixels
@@ -169,7 +167,6 @@ export function wrapLucideIcon(Icon: LucideIcon): LucideIcon {
169167
// Using useStyle hook for functional component theming
170168
const styles = useStyle({
171169
generateStyle,
172-
generateComponentTheme,
173170
params: {
174171
size: semanticSize,
175172
color: colorValue,
@@ -178,7 +175,7 @@ export function wrapLucideIcon(Icon: LucideIcon): LucideIcon {
178175
inline,
179176
themeOverride
180177
},
181-
componentId: 'LucideIcon',
178+
componentId: 'Icon',
182179
displayName: `LucideIcon(${Icon.displayName || Icon.name})`
183180
})
184181

@@ -240,6 +237,5 @@ export function wrapLucideIcon(Icon: LucideIcon): LucideIcon {
240237
return WrappedIcon as LucideIcon
241238
}
242239

243-
export type { LucideIconWrapperProps, InstUIIconProps, LucideIconTheme }
244-
export { default as generateComponentTheme } from './theme'
240+
export type { LucideIconWrapperProps, InstUIIconProps }
245241
export { default as generateStyle } from './styles'

packages/ui-icons-lucide/src/wrapLucideIcon/props.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import type { LucideProps } from 'lucide-react'
2626
import type { ComponentStyle } from '@instructure/emotion'
27-
import type { LucideIconTheme } from './theme'
27+
import type { NewComponentTypes } from '@instructure/ui-themes'
2828

2929
/**
3030
* InstUI-specific props added to Lucide icons.
@@ -111,7 +111,7 @@ export interface InstUIIconProps {
111111
* Theme overrides for this specific icon instance.
112112
* Allows customization of theme variables on a per-component basis.
113113
*/
114-
themeOverride?: Partial<LucideIconTheme>
114+
themeOverride?: Partial<NewComponentTypes['Icon']>
115115
}
116116

117117
/**
@@ -135,5 +135,3 @@ export interface LucideIconWrapperProps
135135
* Generated by the generateStyle function and consumed by the useStyle hook.
136136
*/
137137
export type LucideIconStyle = ComponentStyle<'lucideIcon'>
138-
139-
export { type LucideIconTheme }

packages/ui-icons-lucide/src/wrapLucideIcon/styles.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import type { LucideIconTheme } from './theme'
25+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
2626
import type { LucideIconStyle } from './props'
2727

2828
interface StyleParams {
@@ -31,7 +31,7 @@ interface StyleParams {
3131
rotate?: '0' | '90' | '180' | '270'
3232
bidirectional?: boolean
3333
inline?: boolean
34-
themeOverride?: Partial<LucideIconTheme>
34+
themeOverride?: Partial<NewComponentTypes['Icon']>
3535
}
3636

3737
/**
@@ -42,27 +42,30 @@ interface StyleParams {
4242
*
4343
* @param componentTheme The theme variable object
4444
* @param params The reactive parameters (props that affect styling)
45+
* @param _sharedTokens Shared token object that stores common values for the theme
4546
* @return The final style object, which will be used in the component
4647
*/
4748
const generateStyle = (
48-
componentTheme: LucideIconTheme,
49-
params: StyleParams
49+
componentTheme: NewComponentTypes['Icon'],
50+
params: StyleParams,
51+
_sharedTokens: SharedTokens
5052
): LucideIconStyle => {
5153
const { color, rotate = '0', bidirectional = true, inline = true } = params
5254

5355
// Color mapping (semantic colors from theme)
5456
// Note: Size is no longer applied here - it's passed directly to Lucide as pixels
57+
// Maps InstUI semantic color names to v12 Icon theme properties
5558
const colorVariants = {
5659
inherit: { color: 'inherit' },
57-
primary: { color: componentTheme.primaryColor },
58-
secondary: { color: componentTheme.secondaryColor },
59-
'primary-inverse': { color: componentTheme.primaryInverseColor },
60-
'secondary-inverse': { color: componentTheme.secondaryInverseColor },
60+
primary: { color: componentTheme.baseColor },
61+
secondary: { color: componentTheme.mutedColor },
62+
'primary-inverse': { color: componentTheme.inverseColor },
63+
'secondary-inverse': { color: componentTheme.inverseColor },
6164
success: { color: componentTheme.successColor },
6265
error: { color: componentTheme.errorColor },
6366
warning: { color: componentTheme.warningColor },
64-
alert: { color: componentTheme.alertColor },
65-
brand: { color: componentTheme.brandColor }
67+
alert: { color: componentTheme.infoColor },
68+
brand: { color: componentTheme.infoColor }
6669
}
6770

6871
// Rotation transforms (LTR context)

packages/ui-icons-lucide/src/wrapLucideIcon/theme.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)