11import "./styles.css" ;
2- import { useCallback , useEffect , useState } from "react" ;
2+ import { useCallback , useState } from "react" ;
33import { teethPaths } from "./data" ;
44
55interface TeethProps {
@@ -29,23 +29,55 @@ export interface OdontogramProps {
2929 className ?: string ;
3030 selectedColor ?: string ;
3131 hoverColor ?: string ;
32- theme : "light" | "dark" ,
33- colors : Record < string , string > ,
32+ theme : "light" | "dark" ;
33+ colors : Record < string , string > ;
3434 notation ?: "FDI" | "Universal" | "Palmer" ;
3535}
3636
37-
38- function convertFDIToNotation ( fdi : string , notation : "FDI" | "Universal" | "Palmer" ) {
37+ function convertFDIToNotation (
38+ fdi : string ,
39+ notation : "FDI" | "Universal" | "Palmer" ,
40+ ) {
3941 const num = fdi . replace ( "teeth-" , "" ) ;
4042
4143 const fdiToUniversal : Record < string , number > = {
42- "11" : 8 , "12" : 7 , "13" : 6 , "14" : 5 , "15" : 4 , "16" : 3 , "17" : 2 , "18" : 1 ,
43- "21" : 9 , "22" : 10 , "23" : 11 , "24" : 12 , "25" : 13 , "26" : 14 , "27" : 15 , "28" : 16 ,
44- "31" : 24 , "32" : 23 , "33" : 22 , "34" : 21 , "35" : 20 , "36" : 19 , "37" : 18 , "38" : 17 ,
45- "41" : 25 , "42" : 26 , "43" : 27 , "44" : 28 , "45" : 29 , "46" : 30 , "47" : 31 , "48" : 32 ,
44+ "11" : 8 ,
45+ "12" : 7 ,
46+ "13" : 6 ,
47+ "14" : 5 ,
48+ "15" : 4 ,
49+ "16" : 3 ,
50+ "17" : 2 ,
51+ "18" : 1 ,
52+ "21" : 9 ,
53+ "22" : 10 ,
54+ "23" : 11 ,
55+ "24" : 12 ,
56+ "25" : 13 ,
57+ "26" : 14 ,
58+ "27" : 15 ,
59+ "28" : 16 ,
60+ "31" : 24 ,
61+ "32" : 23 ,
62+ "33" : 22 ,
63+ "34" : 21 ,
64+ "35" : 20 ,
65+ "36" : 19 ,
66+ "37" : 18 ,
67+ "38" : 17 ,
68+ "41" : 25 ,
69+ "42" : 26 ,
70+ "43" : 27 ,
71+ "44" : 28 ,
72+ "45" : 29 ,
73+ "46" : 30 ,
74+ "47" : 31 ,
75+ "48" : 32 ,
4676 } ;
4777
48- if ( notation === "Universal" ) return String ( fdiToUniversal [ num ] ?? num ) ;
78+ if ( notation === "Universal" ) {
79+ return String ( fdiToUniversal [ num ] ?? num ) ;
80+ }
4981
5082 if ( notation === "Palmer" ) {
5183 const quadrant = num [ 0 ] ;
@@ -62,7 +94,6 @@ function convertFDIToNotation(fdi: string, notation: "FDI" | "Universal" | "Palm
6294 return num ;
6395}
6496
65-
6697function getToothNotations ( fdi : string ) {
6798 const num = fdi . replace ( "teeth-" , "" ) ;
6899 const universal = convertFDIToNotation ( fdi , "Universal" ) ;
@@ -74,7 +105,6 @@ function getToothNotations(fdi: string) {
74105 } ;
75106}
76107
77-
78108const Teeth = ( {
79109 name,
80110 outlinePath,
@@ -83,8 +113,7 @@ const Teeth = ({
83113 selected,
84114 onClick,
85115 onKeyDown,
86- children
87-
116+ children,
88117} : TeethProps ) => (
89118 < g
90119 className = { `${ name } ${ selected ? "selected" : "" } ` }
@@ -130,30 +159,26 @@ const Teeth = ({
130159 </ g >
131160) ;
132161
133-
134162const Odontogram : React . FC < OdontogramProps > = ( {
135163 defaultSelected = [ ] ,
136164 onChange,
137165 className = "" ,
138166 theme = "light" ,
139167 colors = { } ,
140168 notation,
141-
142169} ) => {
143-
144170 const themeColors =
145171 theme === "dark"
146172 ? {
147- "--dark-blue" : "#aab6ff" ,
148- "--base-blue" : "#d0d5f6" ,
149- "--light-blue" : "#5361e6" ,
150- }
173+ "--dark-blue" : "#aab6ff" ,
174+ "--base-blue" : "#d0d5f6" ,
175+ "--light-blue" : "#5361e6" ,
176+ }
151177 : {
152- "--dark-blue" : "#3e5edc" ,
153- "--base-blue" : "#8a98be" ,
154- "--light-blue" : "#c6ccf8" ,
155- } ;
156-
178+ "--dark-blue" : "#3e5edc" ,
179+ "--base-blue" : "#8a98be" ,
180+ "--light-blue" : "#c6ccf8" ,
181+ } ;
157182
158183 const [ selected , setSelected ] = useState < Set < string > > (
159184 new Set ( defaultSelected ) ,
@@ -181,7 +206,7 @@ const Odontogram: React.FC<OdontogramProps> = ({
181206 return updated ;
182207 } ) ;
183208 } ,
184- [ onChange ]
209+ [ onChange ] ,
185210 ) ;
186211 const handleKeyDown = useCallback (
187212 ( e : React . KeyboardEvent < SVGGElement > , name : string ) => {
@@ -225,7 +250,7 @@ const Odontogram: React.FC<OdontogramProps> = ({
225250 < div
226251 className = { `Odontogram ${ theme === "dark" ? "dark-theme" : "" } ` }
227252 style = { {
228- ...finalColors as React . CSSProperties ,
253+ ...( finalColors as React . CSSProperties ) ,
229254 width : "100%" ,
230255 maxWidth : 300 ,
231256 margin : "0 auto" ,
@@ -266,12 +291,17 @@ const Odontogram: React.FC<OdontogramProps> = ({
266291 ) ;
267292} ;
268293
269-
270294function mapToCssVars ( colors : Record < string , string | undefined > ) {
271295 const cssVars : Record < string , string > = { } ;
272- if ( colors . darkBlue ) cssVars [ "--dark-blue" ] = colors . darkBlue ;
273- if ( colors . baseBlue ) cssVars [ "--base-blue" ] = colors . baseBlue ;
274- if ( colors . lightBlue ) cssVars [ "--light-blue" ] = colors . lightBlue ;
296+ if ( colors . darkBlue ) {
297+ cssVars [ "--dark-blue" ] = colors . darkBlue ;
298+ }
299+ if ( colors . baseBlue ) {
300+ cssVars [ "--base-blue" ] = colors . baseBlue ;
301+ }
302+ if ( colors . lightBlue ) {
303+ cssVars [ "--light-blue" ] = colors . lightBlue ;
304+ }
275305 return cssVars ;
276306}
277307
0 commit comments