Skip to content

Commit

Permalink
convert ComboBoxItem from class to type, phetsims/sun#768
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jun 27, 2022
1 parent d6eecd4 commit c867dc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
15 changes: 4 additions & 11 deletions js/create/view/TickMarkRangeComboBoxNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Node, RichText } from '../../../../scenery/js/imports.js';
import ComboBox from '../../../../sun/js/ComboBox.js';
import ComboBoxItem from '../../../../sun/js/ComboBoxItem.js';
import HSeparator from '../../../../sun/js/HSeparator.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import ActivationUtterance from '../../../../utterance-queue/js/ActivationUtterance.js';
Expand Down Expand Up @@ -47,15 +46,9 @@ class TickMarkRangeComboBoxNode extends Node {
this.tickMarkRangeProperty = tickMarkRangeProperty;

const items = [
new ComboBoxItem( new RichText( this.tickMarkRangeMap[ 10 ], RANGE_TEXT_OPTIONS ), 10, {
a11yLabel: ratioAndProportionStrings.zeroToTen
} ),
new ComboBoxItem( new RichText( this.tickMarkRangeMap[ 20 ], RANGE_TEXT_OPTIONS ), 20, {
a11yLabel: ratioAndProportionStrings.zeroToTwenty
} ),
new ComboBoxItem( new RichText( this.tickMarkRangeMap[ 30 ], RANGE_TEXT_OPTIONS ), 30, {
a11yLabel: ratioAndProportionStrings.zeroToThirty
} )
{ value: 10, node: new RichText( this.tickMarkRangeMap[ 10 ], RANGE_TEXT_OPTIONS ), a11yLabel: ratioAndProportionStrings.zeroToTen },
{ value: 20, node: new RichText( this.tickMarkRangeMap[ 20 ], RANGE_TEXT_OPTIONS ), a11yLabel: ratioAndProportionStrings.zeroToTwenty },
{ value: 30, node: new RichText( this.tickMarkRangeMap[ 30 ], RANGE_TEXT_OPTIONS ), a11yLabel: ratioAndProportionStrings.zeroToThirty }
];

const widestItem = Math.max( ...items.map( item => item.node.width ) );
Expand All @@ -80,7 +73,7 @@ class TickMarkRangeComboBoxNode extends Node {

// NOTE: The values are [ 10, true ]... so it's typed interestingly.
this.disabledComboBox = new ComboBox<true | number>( new BooleanProperty( value ) as Property<true | number>, [
new ComboBoxItem( new HSeparator( widestItem, { centerY: -5 } ), value, { a11yLabel: ratioAndProportionStrings.a11y.tickMark.tickMarksHidden } ),
{ value: value, node: new HSeparator( widestItem, { centerY: -5 } ), a11yLabel: ratioAndProportionStrings.a11y.tickMark.tickMarksHidden },
items[ 0 ] // add this one to get the proper height of the text.
], new Node(), comboBoxOptions );

Expand Down
15 changes: 8 additions & 7 deletions js/discover/view/ChallengeRatioComboBoxNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import ComboBox from '../../../../sun/js/ComboBox.js';
import ComboBox, { ComboBoxItem } from '../../../../sun/js/ComboBox.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import SoundClip from '../../../../tambo/js/sound-generators/SoundClip.js';
import soundManager from '../../../../tambo/js/soundManager.js';
Expand All @@ -21,7 +21,6 @@ import RatioDescriber from '../../common/view/describers/RatioDescriber.js';
import Property from '../../../../axon/js/Property.js';
import { Color, HBox, Node, NodeOptions, Rectangle, RichText } from '../../../../scenery/js/imports.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import ComboBoxItem from '../../../../sun/js/ComboBoxItem.js';

const SOUND_CLIP_OPTIONS = {
initialOutputLevel: 0.4
Expand Down Expand Up @@ -69,23 +68,23 @@ class ChallengeRatioComboBoxNode extends Node {
color: RAPColors.discoverChallenge1Property.value,
soundClip: new SoundClip( selectionArpeggio001_mp3, SOUND_CLIP_OPTIONS ),
a11yLabel: ratioAndProportionStrings.challenge1,
tandemName: 'challenge1Item'
tandemName: `challenge1${ComboBox.ITEM_TANDEM_NAME_SUFFIX}`
} );
this.ratioToChallengeInfoMap.set( 1 / 3, {
capitalized: ratioAndProportionStrings.challenge2,
lowercase: ratioAndProportionStrings.a11y.discover.challenge2Lowercase,
color: RAPColors.discoverChallenge2Property.value,
soundClip: new SoundClip( selectionArpeggio004_mp3, SOUND_CLIP_OPTIONS ),
a11yLabel: ratioAndProportionStrings.challenge2,
tandemName: 'challenge2Item'
tandemName: `challenge2${ComboBox.ITEM_TANDEM_NAME_SUFFIX}`
} );
this.ratioToChallengeInfoMap.set( 3 / 4, {
capitalized: ratioAndProportionStrings.challenge3,
lowercase: ratioAndProportionStrings.a11y.discover.challenge3Lowercase,
color: RAPColors.discoverChallenge3Property.value,
soundClip: new SoundClip( selectionArpeggio006_mp3, SOUND_CLIP_OPTIONS ),
a11yLabel: ratioAndProportionStrings.challenge3,
tandemName: 'challenge3Item'
tandemName: `challenge3${ComboBox.ITEM_TANDEM_NAME_SUFFIX}`
} );

// Add each soundClip to the soundManager.
Expand Down Expand Up @@ -148,11 +147,13 @@ function createComboBoxItem( targetRatio: number, challengeInfo: ChallengeInfo )
new RichText( challengeInfo.capitalized ) ]
} );

return new ComboBoxItem( node, targetRatio, {
return {
value: targetRatio,
node: node,
soundPlayer: challengeInfo.soundClip,
a11yLabel: challengeInfo.a11yLabel,
tandemName: challengeInfo.tandemName
} );
};
}

ratioAndProportion.register( 'ChallengeRatioComboBoxNode', ChallengeRatioComboBoxNode );
Expand Down

0 comments on commit c867dc6

Please sign in to comment.