Skip to content

Commit

Permalink
Get rid of AccordionBoxOptions from phet-types.d.ts, phetsims/sun#738
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Mar 2, 2022
1 parent 505cb0e commit 30a999a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
20 changes: 8 additions & 12 deletions js/view/AdvancedAccordionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

import merge from '../../../phet-core/js/merge.js';
import { VBox } from '../../../scenery/js/imports.js';
import { Text } from '../../../scenery/js/imports.js';
import { VStrut } from '../../../scenery/js/imports.js';
import { AlignGroup, Text, VBox, VStrut } from '../../../scenery/js/imports.js';
import CCKCConstants from '../CCKCConstants.js';
import circuitConstructionKitCommonStrings from '../circuitConstructionKitCommonStrings.js';
import circuitConstructionKitCommon from '../circuitConstructionKitCommon.js';
Expand All @@ -19,13 +16,13 @@ import CCKCCheckbox from './CCKCCheckbox.js';
import SourceResistanceControl from './SourceResistanceControl.js';
import WireResistivityControl from './WireResistivityControl.js';
import Circuit from '../model/Circuit.js';
import { AlignGroup } from '../../../scenery/js/imports.js';
import Tandem from '../../../tandem/js/Tandem.js';
import optionize from '../../../phet-core/js/optionize.js';

type AdvancedAccordionBoxImplementationOptions = {
showRealBulbsCheckbox: boolean
type SelfOptions = {
showRealBulbsCheckbox?: boolean
};
type AdvancedAccordionBoxOptions = AdvancedAccordionBoxImplementationOptions & CCKCAccordionBoxOptions;
type AdvancedAccordionBoxOptions = SelfOptions & CCKCAccordionBoxOptions;

class AdvancedAccordionBox extends CCKCAccordionBox {

Expand All @@ -36,11 +33,11 @@ class AdvancedAccordionBox extends CCKCAccordionBox {
* @param {Tandem} tandem
* @param {Object} [providedOptions]
*/
constructor( circuit: Circuit, alignGroup: AlignGroup, batteryResistanceControlString: string, tandem: Tandem, providedOptions?: Partial<AdvancedAccordionBoxOptions> ) {
constructor( circuit: Circuit, alignGroup: AlignGroup, batteryResistanceControlString: string, tandem: Tandem, providedOptions?: AdvancedAccordionBoxOptions ) {

const options = merge( {
const options = optionize<AdvancedAccordionBoxOptions, SelfOptions, CCKCAccordionBox>( {
showRealBulbsCheckbox: true
}, providedOptions ) as Required<AdvancedAccordionBoxImplementationOptions>;
}, providedOptions );

const titleConfig = {
fontSize: CCKCConstants.FONT_SIZE,
Expand Down Expand Up @@ -70,7 +67,6 @@ class AdvancedAccordionBox extends CCKCAccordionBox {
titleXSpacing: 0
} );

// @ts-ignore TODO: The AccordionBoxOptions in phet-types isn't compatible with Node's NodeOptions
this.mutate( options );
}
}
Expand Down
29 changes: 17 additions & 12 deletions js/view/CCKCAccordionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,38 @@

import BooleanProperty from '../../../axon/js/BooleanProperty.js';
import merge from '../../../phet-core/js/merge.js';
import optionize from '../../../phet-core/js/optionize.js';
import { HBox } from '../../../scenery/js/imports.js';
import { Node } from '../../../scenery/js/imports.js';
import { HStrut } from '../../../scenery/js/imports.js';
import { Text } from '../../../scenery/js/imports.js';
import AccordionBox from '../../../sun/js/AccordionBox.js';
import AccordionBox, { AccordionBoxOptions } from '../../../sun/js/AccordionBox.js';
import Tandem from '../../../tandem/js/Tandem.js';
import CCKCConstants from '../CCKCConstants.js';
import circuitConstructionKitCommon from '../circuitConstructionKitCommon.js';

// constants
const BUTTON_MARGIN = 8;

type CCKCAccordionBoxOptions = {
strutWidth: number
} & AccordionBoxOptions;
type SelfOptions = {
strutWidth?: number
};
type CCKCAccordionBoxOptions = SelfOptions & AccordionBoxOptions;

class CCKCAccordionBox extends AccordionBox {

/**
* @param {Node} content - the content to display in the accordion box when it is expanded
* @param {string} title - the text to display in the title bar
* @param {Tandem} tandem
* @param {Object} [providedOptions]
* @param content - the content to display in the accordion box when it is expanded
* @param title - the text to display in the title bar
* @param tandem
* @param [providedOptions]
*/
constructor( content: Node, title: string, tandem: Tandem, providedOptions?: Partial<CCKCAccordionBoxOptions> ) {
constructor( content: Node, title: string, tandem: Tandem, providedOptions?: CCKCAccordionBoxOptions ) {

const options = optionize<CCKCAccordionBoxOptions, SelfOptions, AccordionBoxOptions>( {
strutWidth: 10
}, providedOptions );

providedOptions = providedOptions || {};
super( content, merge( {
fill: CCKCConstants.PANEL_COLOR,
cornerRadius: CCKCConstants.CORNER_RADIUS,
Expand All @@ -58,7 +63,7 @@ class CCKCAccordionBox extends AccordionBox {
},
titleNode: new HBox( {
children: [
new HStrut( providedOptions.strutWidth || 10 ),
new HStrut( options.strutWidth ),
new Text( title, {
fontSize: CCKCConstants.FONT_SIZE,
maxWidth: 175,
Expand All @@ -67,7 +72,7 @@ class CCKCAccordionBox extends AccordionBox {
]
} ),
tandem: tandem
}, providedOptions ) );
}, options ) );
}
}

Expand Down

0 comments on commit 30a999a

Please sign in to comment.