PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.6.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.6.6
5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / blocks / src / calendar / edit.js
latepoint / blocks / src / calendar Last commit date
block.json 1 month ago edit.js 1 week ago index-min.js 1 year ago index.js 1 year ago save.js 1 year ago
edit.js
177 lines
1 /**
2 * WordPress components that create the necessary UI elements for the block
3 *
4 * @see https://developer.wordpress.org/block-editor/packages/packages-components/
5 */
6 import {TextControl, SelectControl, Panel, PanelBody, PanelRow} from '@wordpress/components';
7 import {__} from '@wordpress/i18n';
8
9 /**
10 * React hook that is used to mark the block wrapper element.
11 * It provides all the necessary props like the class name.
12 *
13 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
14 */
15 import {
16 useBlockProps,
17 InspectorControls,
18 } from '@wordpress/block-editor';
19 import styled from "@emotion/styled";
20 import IframeEmotionCacheProvider from '../utils/IframeEmotionCacheProvider';
21
22
23 /**
24 * The edit function describes the structure of your block in the context of the
25 * editor. This represents what the editor will render when the block is used.
26 *
27 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
28 *
29 * @param {Object} props Properties passed to the function.
30 * @param {Object} props.attributes Available block attributes.
31 * @param {Function} props.setAttributes Function that updates individual attributes.
32 *
33 * @return {WPElement} Element to render.
34 */
35 export default function Edit({attributes, setAttributes}) {
36 const blockProps = useBlockProps();
37
38 const range = (start, end) => {
39 return Array.from({ length: end - start + 1 }, (_, index) => start + index);
40 }
41
42 const LatepointCalendarWrapper = styled.div`
43 box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.1);
44 border-radius: 4px;
45 border: 1px solid #ddd;
46 border-bottom-color: #bbb;
47 background-color: #fff;
48 padding: 20px;
49 max-width: 400px;
50 `;
51
52 const rangeTypes = [
53 {label: 'Month', value: 'month'},
54 {label: 'Week', value: 'week'},
55 ];
56
57 const LatepointCalendar = styled.div`
58 border: 1px solid #ddd;
59 border-right: none;
60 background: #fbfbfb;
61 `;
62
63 const LatepointBlockCaption = styled.div`
64 font-weight: 500;
65 margin-bottom: 10px;
66 font-size: 12px;
67 text-transform: uppercase;
68 letter-spacing: 1px;
69 `;
70
71 const LCRow = styled.div`
72 display: grid;
73 grid-template-columns: repeat(7, 1fr);
74 `;
75
76 const LCHead = styled.div`
77 border-bottom: 1px solid #ddd;
78 background: #f3f3f3;
79 `;
80
81 const LCCell = styled.div`
82 padding: 10px;
83 text-align: center;
84 border-right: 1px solid #ddd;
85 `;
86 const LCDate = styled.div`
87 padding: 5px;
88 border-radius: 4px;
89 background-color: #e1e1e1;
90 `;
91
92 const LCText = styled.div`
93 padding: 3px;
94 border-radius: 4px;
95 background-color: #ecebeb;
96 `;
97
98 const weekCells = (type) => {
99 return (
100 <>
101 {range(1, 7).map(() => (
102 <LCCell>{type === 'date' ? <LCDate></LCDate> : <LCText></LCText>}</LCCell>
103 ))}
104 </>
105 )
106 };
107
108
109 return (
110 <div {...blockProps}>
111 <InspectorControls>
112 <Panel>
113 <PanelBody title="Latepoint Calendar Settings">
114 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
115 label="Caption"
116 value={attributes.caption || ''}
117 onChange={(value) => setAttributes({caption: value})}
118 />
119 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
120 label={__('Date', 'latepoint')}
121 value={attributes.date || ''}
122 placeholder="YYYY-MM-DD"
123 onChange={(value) => setAttributes({date: value})}
124 />
125 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
126 label="Show Agents"
127 placeholder="Comma separated agent IDs"
128 value={attributes.show_agents || ''}
129 onChange={(value) => setAttributes({show_agents: value})}
130 />
131 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
132 label="Show Services"
133 placeholder="Comma separated service IDs"
134 value={attributes.show_services || ''}
135 onChange={(value) => setAttributes({show_services: value})}
136 />
137 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
138 label="Show Locations"
139 placeholder="Comma separated location IDs"
140 value={attributes.show_locations || ''}
141 onChange={(value) => setAttributes({show_locations: value})}
142 />
143
144 <SelectControl __nextHasNoMarginBottom __next40pxDefaultSize
145 label={__('View', 'latepoint')}
146 value={attributes.view || 'month'}
147 onChange={(value) => setAttributes({view: value})}
148 options={rangeTypes}
149 />
150 </PanelBody>
151 </Panel>
152 </InspectorControls>
153 <IframeEmotionCacheProvider>
154 <LatepointCalendarWrapper>
155 <LatepointBlockCaption>{attributes.caption}</LatepointBlockCaption>
156 <LatepointCalendar>
157 <LCHead>
158 <LCRow>
159 { weekCells('date') }
160 </LCRow>
161 </LCHead>
162
163 { range(1, 4).map(() => (
164 <LCRow>
165 { weekCells('text') }
166 </LCRow>
167 ))}
168
169 </LatepointCalendar>
170
171 </LatepointCalendarWrapper>
172 </IframeEmotionCacheProvider>
173
174 </div>
175 );
176 }
177