(locale: string)
| 139 | abstract getColorChannels(): [ColorChannel, ColorChannel, ColorChannel]; |
| 140 | |
| 141 | getColorName(locale: string): string { |
| 142 | // Convert to oklch color space, which has perceptually uniform lightness across all hues. |
| 143 | let [l, c, h] = toOKLCH(this); |
| 144 | |
| 145 | let strings = |
| 146 | LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary; |
| 147 | if (l > 0.999) { |
| 148 | return strings.getStringForLocale('white', locale); |
| 149 | } |
| 150 | |
| 151 | if (l < 0.001) { |
| 152 | return strings.getStringForLocale('black', locale); |
| 153 | } |
| 154 | |
| 155 | let hue: string; |
| 156 | [hue, l] = this.getOklchHue(l, c, h, locale); |
| 157 | |
| 158 | let lightness = ''; |
| 159 | let chroma = ''; |
| 160 | if (c <= 0.1 && c >= GRAY_THRESHOLD) { |
| 161 | if (l >= 0.7) { |
| 162 | chroma = 'pale'; |
| 163 | } else { |
| 164 | chroma = 'grayish'; |
| 165 | } |
| 166 | } else if (c >= 0.15) { |
| 167 | chroma = 'vibrant'; |
| 168 | } |
| 169 | |
| 170 | if (l < 0.3) { |
| 171 | lightness = 'very dark'; |
| 172 | } else if (l < MAX_DARK_LIGHTNESS) { |
| 173 | lightness = 'dark'; |
| 174 | } else if (l < 0.7) { |
| 175 | // none |
| 176 | } else if (l < 0.85) { |
| 177 | lightness = 'light'; |
| 178 | } else { |
| 179 | lightness = 'very light'; |
| 180 | } |
| 181 | |
| 182 | if (chroma) { |
| 183 | chroma = strings.getStringForLocale(chroma, locale); |
| 184 | } |
| 185 | |
| 186 | if (lightness) { |
| 187 | lightness = strings.getStringForLocale(lightness, locale); |
| 188 | } |
| 189 | |
| 190 | let alpha = this.getChannelValue('alpha'); |
| 191 | let formatter = new LocalizedStringFormatter(locale, strings); |
| 192 | if (alpha < 1) { |
| 193 | let percentTransparent = new NumberFormatter(locale, {style: 'percent'}).format(1 - alpha); |
| 194 | return formatter |
| 195 | .format('transparentColorName', { |
| 196 | lightness, |
| 197 | chroma, |
| 198 | hue, |
nothing calls this directly
no test coverage detected