Skip to content
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

DateTimeControl. Edit button text, with option to customise text #286

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/DateTimeControl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The `DateTimeControl` component provides a date and time picker with timezone in

- `label` (string): The label for the date/time control.
- `id` (string): The ID for the base control.
- `onChange` (Function): Callback function to handle date/time change.
- `onChange` (function): Callback function to handle date/time change.
- `value` (string): The current date/time value in UTC format.
- `editButtonText` (string, optional): The text for the edit/set button.

## Usage

Expand Down
18 changes: 13 additions & 5 deletions src/components/DateTimeControl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ import TimeZone from './timezone';
*
* @param {object} props - Component properties.
* @param {string} props.label - The label for the date/time control.
* @param {string} [props.editButtonText] - The text for the edit/set button. (optional)
* @param {string} props.id - The ID for the base control.
* @param {Function} props.onChange - Callback function to handle date/time change.
* @param {string} props.value - The current date/time value in UTC format.
*
* @returns {ReactNode|null} The DateTimeControl component.
* @returns {React.ReactNode|null} The DateTimeControl component.
*/
function DateTimeControl( { label, id, onChange, value } ) {
function DateTimeControl( {
editButtonText,
label,
id,
onChange,
value,
} ) {
const [ isDatePickerVisible, setIsDatePickerVisible ] = useState( false );
const dateSettings = getDateSettings();
const defaultEditButtonText = value ? __( 'Edit date', 'block-editor-components' ) : __( 'Set date', 'block-editor-components' );

/**
* Convert a date string in the current site local time into a UTC formatted as a MySQL date.
Expand Down Expand Up @@ -63,11 +71,11 @@ function DateTimeControl( { label, id, onChange, value } ) {
) }

<Button
style={ { display: 'block' } }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one… the link was interfering in the same line.

variant="link"
onClick={ () =>
setIsDatePickerVisible( ! isDatePickerVisible ) }
onClick={ () => setIsDatePickerVisible( ! isDatePickerVisible ) }
>
{ __( 'Edit webinar start time/date', 'block-editor-components' ) }
{ editButtonText ? editButtonText : defaultEditButtonText }
</Button>

{ isDatePickerVisible && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/DateTimeControl/timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { __ } from '@wordpress/i18n';
* This component determines the user's timezone offset and compares it with the system timezone offset.
* If they match, it returns null. Otherwise, it displays the timezone abbreviation and details in a tooltip.
*
* @returns {ReactNode|null} The timezone abbreviation and details in a tooltip, or null if the user's timezone matches the system timezone.
* @returns {React.ReactNode|null} The timezone abbreviation and details in a tooltip, or null if the user's timezone matches the system timezone.
*/
const TimeZone = () => {
const { timezone } = getDateSettings();
Expand Down
Loading