-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Match dialog button layout to OS #6044
Changes from all commits
8811afc
9d97d45
344b32d
8065add
bcf06c8
b455d3c
307eba9
d79808e
e8925f7
418986b
d27009a
f100ebd
9166192
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import React from 'react'; | |
// Other dependencies. | ||
import { localize } from '../../../../../nls.js'; | ||
import { Button } from '../../../../../base/browser/ui/positronComponents/button/button.js'; | ||
import * as platform from '../../../../../base/common/platform.js'; | ||
|
||
/** | ||
* OKCancelBackNextActionBarProps interface. | ||
|
@@ -38,31 +39,33 @@ interface ActionBarButtonConfig { | |
* @returns The rendered component. | ||
*/ | ||
export const OKCancelBackNextActionBar = ({ okButtonConfig, cancelButtonConfig, backButtonConfig, nextButtonConfig }: OKCancelBackNextActionBarProps) => { | ||
const cancelButton = (cancelButtonConfig ? | ||
<Button className='action-bar-button' onPressed={cancelButtonConfig.onClick} disabled={cancelButtonConfig.disable ?? false}> | ||
{cancelButtonConfig.title ?? localize('positronCancel', "Cancel")} | ||
</Button> : null); | ||
const okButton = (okButtonConfig ? | ||
<Button className='action-bar-button default' onPressed={okButtonConfig.onClick} disabled={okButtonConfig.disable ?? false}> | ||
{okButtonConfig.title ?? localize('positronOK', "OK")} | ||
</Button> : null); | ||
const nextButton = (nextButtonConfig ? | ||
<Button className='action-bar-button default' onPressed={nextButtonConfig.onClick} disabled={nextButtonConfig.disable ?? false}> | ||
{nextButtonConfig.title ?? localize('positronNext', "Next")} | ||
</Button> : null); | ||
|
||
// Render. | ||
return ( | ||
<div className='ok-cancel-action-bar top-separator'> | ||
<div className='ok-cancel-back-action-bar top-separator'> | ||
<div className='left-actions'> | ||
{backButtonConfig ? | ||
<Button className='button action-bar-button' onPressed={backButtonConfig.onClick} disabled={backButtonConfig.disable ?? false}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that we had this Let me know if this is wrong and we do need it! |
||
<Button className='action-bar-button' onPressed={backButtonConfig.onClick} disabled={backButtonConfig.disable ?? false}> | ||
{backButtonConfig.title ?? localize('positronBack', "Back")} | ||
</Button> : null | ||
} | ||
</div> | ||
<div className='right-actions'> | ||
{cancelButtonConfig ? | ||
<Button className='button action-bar-button' onPressed={cancelButtonConfig.onClick} disabled={cancelButtonConfig.disable ?? false}> | ||
{cancelButtonConfig.title ?? localize('positronCancel', "Cancel")} | ||
</Button> : null | ||
} | ||
{okButtonConfig ? | ||
<Button className='button action-bar-button default' onPressed={okButtonConfig.onClick} disabled={okButtonConfig.disable ?? false}> | ||
{okButtonConfig.title ?? localize('positronOK', "OK")} | ||
</Button> : null | ||
} | ||
{nextButtonConfig ? | ||
<Button className='button action-bar-button default' onPressed={nextButtonConfig.onClick} disabled={nextButtonConfig.disable ?? false}> | ||
{nextButtonConfig.title ?? localize('positronNext', "Next")} | ||
</Button> : null | ||
{platform.isWindows | ||
? <>{nextButton}{okButton}{cancelButton}</> | ||
: <>{cancelButton}{nextButton}{okButton}</> | ||
} | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2025 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
|
||
// React. | ||
import React from 'react'; | ||
|
||
// Other dependencies. | ||
import * as platform from '../../../../../base/common/platform.js'; | ||
|
||
/** | ||
* PlatformNativeDialogActionBarProps interface. | ||
*/ | ||
interface PlatformNativeDialogActionBarProps { | ||
secondaryButton?: React.ReactNode, | ||
primaryButton?: React.ReactNode | ||
} | ||
|
||
/** | ||
* PlatformNativeDialogActionBar component. | ||
* @param props A PlatformNativeDialogActionBarProps that contains the component properties. | ||
* @returns The rendered component. | ||
*/ | ||
export const PlatformNativeDialogActionBar = ({ secondaryButton, primaryButton }: PlatformNativeDialogActionBarProps) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a super basic component that renders the primary and secondary button in the order most common for a given OS. Windows always positions the cancel/secondary button after the primary button and the inverse is true for Mac. |
||
// Render. | ||
return ( | ||
<> | ||
{ | ||
platform.isWindows | ||
? <>{primaryButton}{secondaryButton}</> | ||
: <>{secondaryButton}{primaryButton}</> | ||
} | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// CSS. | ||
import './positronModalDialog.css'; | ||
import './confirmDeleteModalDialog.css'; | ||
|
||
// React. | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
// Other dependencies. | ||
import { localize } from '../../../../nls.js'; | ||
import { Button } from '../../../../base/browser/ui/positronComponents/button/button.js'; | ||
import { ContentArea } from './components/contentArea.js'; | ||
import { PositronModalDialog, PositronModalDialogProps } from './positronModalDialog.js'; | ||
import { PlatformNativeDialogActionBar } from './components/platformNativeDialogActionBar.js'; | ||
|
||
/** | ||
* ConfirmDeleteModalDialogProps interface. | ||
*/ | ||
export interface ConfirmDeleteModalDialogProps extends PositronModalDialogProps { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This modal has been simplified in its usage so its shown when we want a user to see a confirmation modal for a delete action. We always provide the delete action now and optionally can provide a different label for the delete action. The |
||
title: string; | ||
cancelButtonTitle?: string; | ||
deleteActionTitle?: string | ||
onCancel: () => (void | Promise<void>); | ||
onDeleteAction: () => (void | Promise<void>); | ||
} | ||
|
||
/** | ||
* ConfirmDeleteModalDialog component. | ||
* @param props A PropsWithChildren<ConfirmDeleteModalDialogProps> that contains the component | ||
* properties. | ||
* @returns The rendered component. | ||
*/ | ||
export const ConfirmDeleteModalDialog = (props: PropsWithChildren<ConfirmDeleteModalDialogProps>) => { | ||
const cancelButton = ( | ||
<Button | ||
className='action-bar-button' | ||
onPressed={async () => await props.onCancel()} | ||
> | ||
{props.cancelButtonTitle ?? localize('positron.cancel', "Cancel")} | ||
</Button> | ||
); | ||
const deleteButton = ( | ||
<Button | ||
className='action-bar-button default' | ||
onPressed={async () => await props.onDeleteAction()} | ||
> | ||
{props.deleteActionTitle ?? localize('positron.delete', "Delete")} | ||
</Button> | ||
); | ||
|
||
// Render. | ||
return ( | ||
<PositronModalDialog {...props}> | ||
<ContentArea> | ||
{props.children} | ||
</ContentArea> | ||
<div className='action-bar top-separator'> | ||
<div className='left-actions'> | ||
</div> | ||
<div className='right-actions'> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we explicitly want the button order here to be delete/cancel. This button order may seem odd to non-windows users now that we are trying to match native OS button ordering but I have left it as is for now because it looked like the button order was intentionally made so delete was the secondary action. I think we should change it to be native to the OS but would love to get thoughts on this from others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @juliasilge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to OS-applicable button ordering! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With all this work to make our modals consistent with OS norms, it seems a shame to not really be thorough and go the whole way. I know there was some concern about it being too easy to take a destructive action, but it's still multiple user actions to actually delete, for example, the variables content. I would advocate for OS-consistent button ordering. |
||
<PlatformNativeDialogActionBar secondaryButton={cancelButton} primaryButton={deleteButton} /> | ||
</div> | ||
</div> | ||
</PositronModalDialog> | ||
); | ||
}; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the
ok-cancel-action-bar
class took-cancel-back-action-bar
to avoid name collisions. The layout is different for this action bar and theOkCancelActionBar
:justify-content: space-between
vsjustify-content: end
.This change prevents the
OKCancelModalDialog
using theOkCancelActionBar
from having the buttons positioned incorrectly. I noticed during my testing that the styles from this sheet were overriding the styles inOkCancelActionBar
which we don't want anymore.Here's a screenshot of what was happening: