|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2015 - present Instructure, Inc. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | +'use client' |
| 25 | +import React from 'react' |
| 26 | +import { CustomIcons, LucideIcons } from '@instructure/ui-icons' |
| 27 | +import type { InstUIIconProps } from '@instructure/ui-icons' |
| 28 | + |
| 29 | +type IconComponent = React.ComponentType<InstUIIconProps> |
| 30 | +type IconEntry = [string, IconComponent] |
| 31 | + |
| 32 | +const COLORS: InstUIIconProps['color'][] = [ |
| 33 | + 'ai', |
| 34 | + 'baseColor', |
| 35 | + 'errorColor', |
| 36 | + 'successColor', |
| 37 | + 'warningColor', |
| 38 | + 'infoColor', |
| 39 | + 'mutedColor', |
| 40 | + 'accentVioletColor' |
| 41 | +] |
| 42 | +const SIZES: InstUIIconProps['size'][] = [ |
| 43 | + 'xs', |
| 44 | + 'sm', |
| 45 | + 'md', |
| 46 | + 'lg', |
| 47 | + 'xl', |
| 48 | + '2xl', |
| 49 | + 'illu-sm', |
| 50 | + 'illu-md', |
| 51 | + 'illu-lg' |
| 52 | +] |
| 53 | + |
| 54 | +const sample = (entries: IconEntry[], n = 5): IconEntry[] => |
| 55 | + Array.from( |
| 56 | + { length: n }, |
| 57 | + (_, i) => entries[Math.floor((i * entries.length) / n)] |
| 58 | + ) |
| 59 | + |
| 60 | +const CUSTOM = sample( |
| 61 | + Object.entries(CustomIcons).filter(([name]) => |
| 62 | + name.endsWith('InstUIIcon') |
| 63 | + ) as IconEntry[] |
| 64 | +) |
| 65 | +const LUCIDE = sample( |
| 66 | + Object.entries(LucideIcons).filter(([name]) => |
| 67 | + name.endsWith('InstUIIcon') |
| 68 | + ) as IconEntry[] |
| 69 | +) |
| 70 | + |
| 71 | +function IconGrid({ |
| 72 | + icons, |
| 73 | + color, |
| 74 | + size = 'md' |
| 75 | +}: { |
| 76 | + icons: IconEntry[] |
| 77 | + color: InstUIIconProps['color'] |
| 78 | + size?: InstUIIconProps['size'] |
| 79 | +}) { |
| 80 | + return ( |
| 81 | + <div className="flex flex-wrap gap-1"> |
| 82 | + {icons.map(([name, Icon]) => ( |
| 83 | + <div key={name} className="flex flex-col items-center gap-1 p-1"> |
| 84 | + <Icon size={size} color={color} title={name} /> |
| 85 | + <span |
| 86 | + style={{ fontSize: '8px', maxWidth: '76px' }} |
| 87 | + className="text-gray-500 text-center break-words leading-tight" |
| 88 | + > |
| 89 | + {name.replace('InstUIIcon', '')} |
| 90 | + </span> |
| 91 | + </div> |
| 92 | + ))} |
| 93 | + </div> |
| 94 | + ) |
| 95 | +} |
| 96 | + |
| 97 | +function SizeRow({ |
| 98 | + Icon, |
| 99 | + name, |
| 100 | + color |
| 101 | +}: { |
| 102 | + Icon: IconComponent |
| 103 | + name: string |
| 104 | + color: InstUIIconProps['color'] |
| 105 | +}) { |
| 106 | + return ( |
| 107 | + <div className="flex items-end flex-wrap gap-3"> |
| 108 | + {SIZES.map((size) => ( |
| 109 | + <div key={size} className="flex flex-col items-center gap-1 p-1"> |
| 110 | + <Icon size={size} color={color} title={name} /> |
| 111 | + <span style={{ fontSize: '8px' }} className="text-gray-500"> |
| 112 | + {size} |
| 113 | + </span> |
| 114 | + </div> |
| 115 | + ))} |
| 116 | + </div> |
| 117 | + ) |
| 118 | +} |
| 119 | + |
| 120 | +function SectionHeader({ children }: { children: React.ReactNode }) { |
| 121 | + return ( |
| 122 | + <p className="text-xs font-bold mt-7 mb-2 pb-1 border-b border-gray-300 text-gray-700"> |
| 123 | + {children} |
| 124 | + </p> |
| 125 | + ) |
| 126 | +} |
| 127 | + |
| 128 | +export default function CustomIconsPage() { |
| 129 | + return ( |
| 130 | + <main className="axe-test p-6 font-sans"> |
| 131 | + <h1 className="text-sm font-bold mb-1"> |
| 132 | + Custom icons (sample of {CUSTOM.length}) |
| 133 | + </h1> |
| 134 | + |
| 135 | + {COLORS.map((color) => ( |
| 136 | + <React.Fragment key={color}> |
| 137 | + <SectionHeader>color={color}</SectionHeader> |
| 138 | + <IconGrid icons={CUSTOM} color={color} /> |
| 139 | + </React.Fragment> |
| 140 | + ))} |
| 141 | + |
| 142 | + {SIZES.map((size) => ( |
| 143 | + <React.Fragment key={size}> |
| 144 | + <SectionHeader>size={size}, color=baseColor</SectionHeader> |
| 145 | + <IconGrid icons={CUSTOM} color="baseColor" size={size} /> |
| 146 | + </React.Fragment> |
| 147 | + ))} |
| 148 | + |
| 149 | + <SectionHeader> |
| 150 | + Size scale — AiInfo (stroke) + BellSolid (filled) + CanvasLogo (brand) |
| 151 | + </SectionHeader> |
| 152 | + <SizeRow Icon={CustomIcons.AiInfoInstUIIcon} name="AiInfo" color="ai" /> |
| 153 | + <SizeRow |
| 154 | + Icon={CustomIcons.BellSolidInstUIIcon} |
| 155 | + name="BellSolid" |
| 156 | + color="ai" |
| 157 | + /> |
| 158 | + <SizeRow |
| 159 | + Icon={CustomIcons.CanvasLogoInstUIIcon} |
| 160 | + name="CanvasLogo" |
| 161 | + color="baseColor" |
| 162 | + /> |
| 163 | + |
| 164 | + <h1 className="text-sm font-bold mt-10 mb-1"> |
| 165 | + Lucide icons (sample of {LUCIDE.length}) |
| 166 | + </h1> |
| 167 | + |
| 168 | + {COLORS.map((color) => ( |
| 169 | + <React.Fragment key={color}> |
| 170 | + <SectionHeader>color={color}</SectionHeader> |
| 171 | + <IconGrid icons={LUCIDE} color={color} /> |
| 172 | + </React.Fragment> |
| 173 | + ))} |
| 174 | + |
| 175 | + <SectionHeader>Size scale — Heart, color=ai</SectionHeader> |
| 176 | + <SizeRow Icon={LucideIcons.HeartInstUIIcon} name="Heart" color="ai" /> |
| 177 | + </main> |
| 178 | + ) |
| 179 | +} |
0 commit comments