Skip to content

Commit 2f8c2c9

Browse files
authored
Merge pull request #2 from 10up/feature/person-single-template
WIP Feature: Person single template
2 parents 93e5f44 + d552548 commit 2f8c2c9

File tree

43 files changed

+1028
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1028
-15
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* PersonBirthplace post meta
4+
*
5+
* @package TenUpPlugin
6+
*/
7+
8+
namespace TenUpPlugin\PostMeta;
9+
10+
use TenUpPlugin\PostTypes\Person;
11+
12+
/**
13+
* PersonBirthplace meta field.
14+
*/
15+
class PersonBirthplace extends AbstractPostMeta {
16+
17+
/**
18+
* The meta_key name.
19+
*
20+
* @var string
21+
*/
22+
const META_KEY = 'tenup_person_birthplace';
23+
24+
/**
25+
* Get the field description.
26+
*
27+
* @return string
28+
*/
29+
public function get_description(): string {
30+
return __( 'Person Birthplace', 'tenup' );
31+
}
32+
33+
/**
34+
* Get the post types.
35+
*
36+
* @return array
37+
*/
38+
public function get_post_types(): array {
39+
return [
40+
Person::get_name(),
41+
];
42+
}
43+
44+
/**
45+
* Checks whether the Module should run within the current context.
46+
*
47+
* @return bool
48+
*/
49+
public function can_register(): bool {
50+
return true;
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* PersonBorn post meta
4+
*
5+
* @package TenUpPlugin
6+
*/
7+
8+
namespace TenUpPlugin\PostMeta;
9+
10+
use TenUpPlugin\PostTypes\Person;
11+
12+
/**
13+
* PersonBorn meta field.
14+
*/
15+
class PersonBorn extends AbstractPostMeta {
16+
17+
/**
18+
* The meta_key name.
19+
*
20+
* @var string
21+
*/
22+
const META_KEY = 'tenup_person_born';
23+
24+
/**
25+
* Get the field description.
26+
*
27+
* @return string
28+
*/
29+
public function get_description(): string {
30+
return __( 'Person Born', 'tenup' );
31+
}
32+
33+
/**
34+
* Get the post types.
35+
*
36+
* @return array
37+
*/
38+
public function get_post_types(): array {
39+
return [
40+
Person::get_name(),
41+
];
42+
}
43+
44+
/**
45+
* Checks whether the Module should run within the current context.
46+
*
47+
* @return bool
48+
*/
49+
public function can_register(): bool {
50+
return true;
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* PersonDeathplace post meta
4+
*
5+
* @package TenUpPlugin
6+
*/
7+
8+
namespace TenUpPlugin\PostMeta;
9+
10+
use TenUpPlugin\PostTypes\Person;
11+
12+
/**
13+
* PersonDeathplace meta field.
14+
*/
15+
class PersonDeathplace extends AbstractPostMeta {
16+
17+
/**
18+
* The meta_key name.
19+
*
20+
* @var string
21+
*/
22+
const META_KEY = 'tenup_person_deathplace';
23+
24+
/**
25+
* Get the field description.
26+
*
27+
* @return string
28+
*/
29+
public function get_description(): string {
30+
return __( 'Person Deathplace', 'tenup' );
31+
}
32+
33+
/**
34+
* Get the post types.
35+
*
36+
* @return array
37+
*/
38+
public function get_post_types(): array {
39+
return [
40+
Person::get_name(),
41+
];
42+
}
43+
44+
/**
45+
* Checks whether the Module should run within the current context.
46+
*
47+
* @return bool
48+
*/
49+
public function can_register(): bool {
50+
return true;
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* PersonDied post meta
4+
*
5+
* @package TenUpPlugin
6+
*/
7+
8+
namespace TenUpPlugin\PostMeta;
9+
10+
use TenUpPlugin\PostTypes\Person;
11+
12+
/**
13+
* PersonDied meta field.
14+
*/
15+
class PersonDied extends AbstractPostMeta {
16+
17+
/**
18+
* The meta_key name.
19+
*
20+
* @var string
21+
*/
22+
const META_KEY = 'tenup_person_died';
23+
24+
/**
25+
* Get the field description.
26+
*
27+
* @return string
28+
*/
29+
public function get_description(): string {
30+
return __( 'Person Died', 'tenup' );
31+
}
32+
33+
/**
34+
* Get the post types.
35+
*
36+
* @return array
37+
*/
38+
public function get_post_types(): array {
39+
return [
40+
Person::get_name(),
41+
];
42+
}
43+
44+
/**
45+
* Checks whether the Module should run within the current context.
46+
*
47+
* @return bool
48+
*/
49+
public function can_register(): bool {
50+
return true;
51+
}
52+
}
1.35 MB
Loading
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* eslint-disable @wordpress/no-unsafe-wp-apis */
2+
/**
3+
* WordPress dependencies.
4+
*/
5+
import {
6+
Button,
7+
DateTimePicker,
8+
Dropdown,
9+
__experimentalHeading as Heading,
10+
__experimentalHStack as HStack,
11+
} from '@wordpress/components';
12+
import { closeSmall } from '@wordpress/icons';
13+
import { __ } from '@wordpress/i18n';
14+
15+
/**
16+
* Formats a date string into the desired display format.
17+
*
18+
* @param {string} date The date string to be formatted.
19+
* @returns {string} The formatted date string.
20+
*/
21+
const formatDate = (date) => {
22+
const options = {
23+
year: 'numeric',
24+
month: 'short',
25+
day: 'numeric',
26+
};
27+
28+
let formattedDate = new Date(date);
29+
formattedDate = formattedDate.toLocaleDateString('en-US', options);
30+
31+
return formattedDate;
32+
};
33+
34+
/**
35+
* Renders a label and button opening a DateTime Popover to be used in a sidebar settings panel.
36+
*
37+
* @param {object} props Component props.
38+
* @param {string} props.date The date to be displayed.
39+
* @param {Function} props.setDate The function to be called when the date is changed.
40+
* @param {string} props.label The label for the DateTimePopover.
41+
* @returns {Function} The DateTimePopover component.
42+
*/
43+
const DateTimePopover = ({ date, setDate, label }) => {
44+
return (
45+
<Dropdown
46+
style={{ width: '100%' }}
47+
popoverProps={{ offset: 36, placement: 'left-end' }}
48+
renderToggle={({ isOpen, onToggle }) => (
49+
<HStack justify="flex-start" alignment="top">
50+
<div className="editor-post-panel__row-label">{__(label, 'tenup')}</div>
51+
<Button
52+
aria-expanded={isOpen}
53+
onClick={onToggle}
54+
size="compact"
55+
variant="tertiary"
56+
>
57+
{date ? formatDate(date) : __('Choose a date', 'tenup')}
58+
</Button>
59+
</HStack>
60+
)}
61+
renderContent={({ onClose }) => (
62+
<div style={{ padding: '16px' }}>
63+
<HStack
64+
justify="space-between"
65+
className="block-editor-inspector-popover-header"
66+
>
67+
<Heading level={2} size={13}>
68+
{__(label, 'tenup')}
69+
</Heading>
70+
<HStack
71+
justify="flex-end"
72+
align="center"
73+
style={{ 'max-width': 'fit-content' }}
74+
>
75+
<Button
76+
onClick={() => setDate('')}
77+
size="small"
78+
variant="link"
79+
isDestructive
80+
>
81+
{__('Clear', 'tenup')}
82+
</Button>
83+
<Button
84+
size="small"
85+
className="block-editor-inspector-popover-header__action"
86+
label={__('Close', 'tenup')}
87+
icon={closeSmall}
88+
onClick={onClose}
89+
/>
90+
</HStack>
91+
</HStack>
92+
<DateTimePicker
93+
label={__(label, 'tenup')}
94+
onChange={setDate}
95+
currentDate={date}
96+
is12Hour
97+
/>
98+
</div>
99+
)}
100+
/>
101+
);
102+
};
103+
104+
export default DateTimePopover;

themes/10up-block-theme/assets/js/block-components/PostMeta/MovieMPARating.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const MovieMPARating = ({ postMetaProps, ...restProps }) => {
3434
options={options}
3535
onChange={(value) => setMeta(value)}
3636
__next40pxDefaultSize
37+
__nextHasNoMarginBottom
3738
{...restProps}
3839
/>
3940
)}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* WordPress dependencies.
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
import { TextControl } from '@wordpress/components';
6+
7+
/**
8+
* External dependencies.
9+
*/
10+
import { PostMeta } from '@10up/block-components';
11+
12+
/**
13+
* PersonBirthplace component.
14+
*
15+
* @param {object} props Component props.
16+
* @param {object} props.postMetaProps Props to use on the 10up PostMeta component.
17+
* @param {object} props.restProps Rest of the props to pass to the control component.
18+
* @returns {Function} The rendered component.
19+
*/
20+
const PersonBirthplace = ({ postMetaProps, ...restProps }) => {
21+
return (
22+
<PostMeta metaKey="tenup_person_birthplace" {...postMetaProps}>
23+
{(meta, setMeta) => (
24+
<TextControl
25+
label={__('Birthplace', 'tenup')}
26+
help={__('City, State, Country', 'tenup')}
27+
onChange={(value) => setMeta(value)}
28+
value={meta}
29+
__next40pxDefaultSize
30+
{...restProps}
31+
/>
32+
)}
33+
</PostMeta>
34+
);
35+
};
36+
37+
export default PersonBirthplace;

0 commit comments

Comments
 (0)