@@ -2,6 +2,7 @@ import copy from "copy-to-clipboard";
22import jsoncrush from "jsoncrush" ;
33import { getNpcOptionsValues , Npc , NpcGenerateOptions } from "npc-generator" ;
44import { Component } from "react" ;
5+ import { cs } from "./core/classSet" ;
56import styles from "./UserInput.module.css" ;
67
78const { alignments, occupations, classes, genders, plothooks, professions, races } = getNpcOptionsValues ( ) ;
@@ -15,6 +16,7 @@ interface IProps {
1516interface IState {
1617 npcOptions : NpcGenerateOptions ;
1718 wasCopiedToClipboard ?: boolean ;
19+ isExpanded : boolean ;
1820}
1921
2022type UserOption = {
@@ -104,9 +106,21 @@ export default class UserInput extends Component<IProps, IState> {
104106 super ( props ) ;
105107 this . state = {
106108 npcOptions : { } ,
109+ isExpanded : localStorage . getItem ( "isExpanded" ) === "true" ,
107110 } ;
108111 }
109112
113+ toggleExpand = ( ) => {
114+ this . setState (
115+ ( prevState ) => ( {
116+ isExpanded : ! prevState . isExpanded ,
117+ } ) ,
118+ ( ) => {
119+ localStorage . setItem ( "isExpanded" , this . state . isExpanded . toString ( ) ) ;
120+ } ,
121+ ) ;
122+ } ;
123+
110124 onSubmit = ( event : React . FormEvent ) => {
111125 event . preventDefault ( ) ;
112126 this . props . generate ( this . state . npcOptions ) ;
@@ -181,7 +195,7 @@ export default class UserInput extends Component<IProps, IState> {
181195 return (
182196 < button
183197 type = "button"
184- className = { ` ${ styles . button } ${ styles . buttonOutline } ${ styles . buttonOutlinePrimary } ` }
198+ className = { styles . buttonSecondary }
185199 title = "Copied to clipboard"
186200 data-test = "copy-button"
187201 onBlur = { this . handleCopyBlur }
@@ -194,7 +208,7 @@ export default class UserInput extends Component<IProps, IState> {
194208 return (
195209 < button
196210 type = "button"
197- className = { ` ${ styles . button } ${ styles . buttonOutline } ${ styles . buttonOutlineSecondary } ` }
211+ className = { styles . buttonSecondary }
198212 title = "Copy character to clipboard"
199213 data-test = "copy-button"
200214 onClick = { this . copyNpcToClipboard }
@@ -205,6 +219,8 @@ export default class UserInput extends Component<IProps, IState> {
205219 }
206220
207221 render ( ) {
222+ const { isExpanded } = this . state ;
223+
208224 const npcOptions = userOptions . map ( ( userOption ) => {
209225 const enable = ! ( userOption . condition && ! userOption . condition ( this . state . npcOptions ) ) ;
210226
@@ -263,25 +279,26 @@ export default class UserInput extends Component<IProps, IState> {
263279
264280 return (
265281 < form onSubmit = { this . onSubmit } >
266- { npcOptions }
282+ < div className = { cs ( styles . optionsContainer , isExpanded ? styles . expanded : styles . collapsed ) } > { npcOptions } </ div >
267283 < div className = { styles . buttonGroup } >
268- < button type = "submit" className = { ` ${ styles . button } ${ styles . buttonPrimary } ` } data-test = "generate-button" >
284+ < button type = "submit" className = { styles . buttonPrimary } data-test = "generate-button" >
269285 Generate
270286 </ button >
271- { this . renderCopyToClipboardButton ( ) }
272- < button type = "button" className = { `${ styles . button } ${ styles . buttonOutline } ${ styles . buttonOutlineSecondary } ` } onClick = { this . downloadTxtFile } >
273- Download
274- </ button >
275- < button type = "button" className = { `${ styles . button } ${ styles . buttonOutline } ${ styles . buttonOutlineSecondary } ` } onClick = { this . props . onToggleHistory } >
276- History
287+ < div className = { cs ( styles . secondaryButtons , isExpanded ? styles . expanded : styles . collapsed ) } >
288+ { this . renderCopyToClipboardButton ( ) }
289+ < button type = "button" className = { styles . buttonSecondary } onClick = { this . downloadTxtFile } >
290+ Download
291+ </ button >
292+ < button type = "button" className = { styles . buttonSecondary } onClick = { this . props . onToggleHistory } >
293+ History
294+ </ button >
295+ < a className = { cs ( styles . buttonSecondary , styles . bookmarkButton ) } href = { npcDataUrl . toString ( ) } data-test = "bookmark-button" >
296+ 🔗 Bookmark
297+ </ a >
298+ </ div >
299+ < button type = "button" className = { cs ( styles . buttonSecondary , styles . expandButton ) } onClick = { this . toggleExpand } >
300+ { isExpanded ? "Hide Options ▲" : "Show Options ▼" }
277301 </ button >
278- < a
279- className = { `${ styles . button } ${ styles . buttonOutline } ${ styles . buttonOutlineSecondary } ${ styles . bookmarkButton } ` }
280- href = { npcDataUrl . toString ( ) }
281- data-test = "bookmark-button"
282- >
283- 🔗 Bookmark
284- </ a >
285302 </ div >
286303 </ form >
287304 ) ;
0 commit comments