Skip to content

Commit

Permalink
chore: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan committed May 5, 2021
1 parent 6b0c918 commit cd35cfd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 59 deletions.
14 changes: 5 additions & 9 deletions src/lib/viewers/box3d/model3d/Model3DViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ class Model3DViewer extends Box3DViewer {
*/
handleSelectAnimationClip(clipId) {
this.renderer.setAnimationClip(clipId);

if (this.controls && this.getViewerOption('useReactControls')) {
this.setAnimationState(false);
this.renderUI();
}
this.setAnimationState(false);
}

/**
Expand Down Expand Up @@ -300,15 +296,15 @@ class Model3DViewer extends Box3DViewer {
*/
handleToggleAnimation(play) {
this.setAnimationState(play);

if (this.controls && this.getViewerOption('useReactControls')) {
this.renderUI();
}
}

setAnimationState(play) {
this.isAnimationPlaying = play;
this.renderer.toggleAnimation(this.isAnimationPlaying);

if (this.controls && this.getViewerOption('useReactControls')) {
this.renderUI();
}
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/lib/viewers/controls/model3d/AnimationClipsControl.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
.bp-SettingsFlyout {
right: auto;
left: 0;
max-height: 200px;
overflow-x: hidden;
overflow-y: auto;
max-width: 240px;
}
}

.bp-AnimationClipsControl-radioItem {
.bp-SettingsRadioItem-value {
max-width: 183px;
max-width: 180px;
overflow-x: hidden;
font-size: 13px;
white-space: nowrap;
text-overflow: ellipsis;
}
Expand Down
9 changes: 4 additions & 5 deletions src/lib/viewers/controls/model3d/AnimationClipsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const padLeft = (x: number, width: number): string => {
return x.length >= width ? x : new Array(width - x.length + 1).join('0') + x;
};

export const formatDurationStr = (duration: number): string => {
export const formatDuration = (duration: number): string => {
let secondsLeft = Math.floor(duration);
const hours = Math.floor(secondsLeft / 3600);
const hoursStr = padLeft(hours.toString(), 2);
Expand All @@ -40,16 +40,15 @@ export default function AnimationClipsControl({
onAnimationClipSelect,
}: Props): JSX.Element {
return (
<Settings className="bp-AnimationClipsControl" disableTransitions={false} icon={AnimationClipsToggle}>
<Settings className="bp-AnimationClipsControl" icon={AnimationClipsToggle}>
<Settings.Menu name={Menu.MAIN}>
{animationClips.map(({ duration, id, name }) => {
const isSelected = id === currentAnimationClipId;
return (
<Settings.RadioItem
key={id}
className="bp-AnimationClipsControl-radioItem"
isSelected={isSelected}
label={`${formatDurationStr(duration)} ${name}`}
isSelected={id === currentAnimationClipId}
label={`${formatDuration(duration)} ${name}`}
onChange={onAnimationClipSelect}
value={id}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('AnimationClipsControl', () => {

expect(wrapper.find(Settings).props()).toMatchObject({
className: 'bp-AnimationClipsControl',
disableTransitions: false,
icon: AnimationClipsToggle,
});
expect(wrapper.exists(Settings.Menu)).toBe(true);
Expand Down
6 changes: 1 addition & 5 deletions src/lib/viewers/controls/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { decodeKeydown } from '../../../util';

export type Props = React.PropsWithChildren<{
className?: string;
disableTransitions?: boolean;
icon?: React.ReactNode;
}>;

export default function Settings({
children,
className,
disableTransitions = false,
icon: ToggleIcon = SettingsToggle,
...rest
}: Props): JSX.Element | null {
Expand Down Expand Up @@ -88,9 +86,7 @@ export default function Settings({
>
<SettingsContext.Provider value={{ activeMenu, activeRect, setActiveMenu, setActiveRect }}>
<ToggleIcon ref={buttonElRef} isOpen={isOpen} onClick={handleClick} />
<SettingsFlyout disableTransitions={disableTransitions} isOpen={isOpen}>
{children}
</SettingsFlyout>
<SettingsFlyout isOpen={isOpen}>{children}</SettingsFlyout>
</SettingsContext.Provider>
</div>
);
Expand Down
12 changes: 3 additions & 9 deletions src/lib/viewers/controls/settings/SettingsFlyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ import './SettingsFlyout.scss';

export type Props = React.PropsWithChildren<{
className?: string;
disableTransitions?: boolean;
isOpen: boolean;
}>;

export default function SettingsFlyout({
children,
className,
disableTransitions = false,
isOpen,
}: Props): JSX.Element {
export default function SettingsFlyout({ children, className, isOpen }: Props): JSX.Element {
const [isTransitioning, setIsTransitioning] = React.useState(false);
const flyoutElRef = React.useRef<HTMLDivElement>(null);
const { activeRect = { height: 'auto', width: 'auto' } } = React.useContext(SettingsContext);
const { height, width } = disableTransitions ? { height: 'auto', width: 'auto' } : activeRect;
const { activeRect } = React.useContext(SettingsContext);
const { height, width } = activeRect || { height: 'auto', width: 'auto' };

React.useEffect(() => {
const { current: flyoutEl } = flyoutElRef;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/viewers/controls/settings/SettingsRadioItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type Value = boolean | number | string;

function SettingsRadioItem<V extends Value>(props: Props<V>, ref: React.Ref<Ref>): JSX.Element {
const { className, isSelected, label, onChange, value } = props;
const displayedValue = label || value;

const handleClick = (): void => {
onChange(value);
Expand Down Expand Up @@ -46,7 +47,9 @@ function SettingsRadioItem<V extends Value>(props: Props<V>, ref: React.Ref<Ref>
<div className="bp-SettingsRadioItem-check">
<IconCheckMark24 className="bp-SettingsRadioItem-check-icon" height={16} width={16} />
</div>
<div className="bp-SettingsRadioItem-value">{label || value}</div>
<div className="bp-SettingsRadioItem-value" title={displayedValue}>
{displayedValue}
</div>
</div>
);
}
Expand Down
14 changes: 0 additions & 14 deletions src/lib/viewers/controls/settings/__tests__/Settings-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,6 @@ describe('Settings', () => {
expect(wrapper.exists(SettingsToggle)).toBe(true);
});

describe('disableTransitions prop', () => {
test('should default disableTransitions to false', () => {
const wrapper = getWrapper();

expect(wrapper.find(SettingsFlyout).prop('disableTransitions')).toBe(false);
});

test('should pass disableTransitions to along to SettingsFlyout', () => {
const wrapper = getWrapper({ disableTransitions: true });

expect(wrapper.find(SettingsFlyout).prop('disableTransitions')).toBe(true);
});
});

describe('icon prop', () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function CustomIcon({ isOpen, ...rest }: object, ref: React.Ref<HTMLDivElement>): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,5 @@ describe('SettingsFlyout', () => {

expect(wrapper.getDOMNode()).toHaveClass('bp-SettingsFlyout');
});

test('should only return default height and width if disableTransitions is true', () => {
const activeRect = { bottom: 0, left: 0, height: 100, right: 0, top: 0, width: 100 };
const wrapper = getWrapper({ disableTransitions: true }, { activeRect });

expect(wrapper.childAt(0).prop('style')).toEqual({
height: 'auto',
width: 'auto',
});
});
});
});

0 comments on commit cd35cfd

Please sign in to comment.