Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-includes/functions.php on line 6170

Deprecated: Creation of dynamic property ACF::$fields is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/fields.php on line 138

Deprecated: Creation of dynamic property acf_loop::$loops is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/loop.php on line 28

Deprecated: Creation of dynamic property ACF::$loop is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/loop.php on line 269

Deprecated: Creation of dynamic property ACF::$revisions is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/revisions.php on line 387

Deprecated: Creation of dynamic property acf_validation::$errors is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/validation.php on line 28

Deprecated: Creation of dynamic property ACF::$validation is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/validation.php on line 215

Deprecated: Creation of dynamic property acf_form_customizer::$preview_values is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 28

Deprecated: Creation of dynamic property acf_form_customizer::$preview_fields is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 29

Deprecated: Creation of dynamic property acf_form_customizer::$preview_errors is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 30

Deprecated: Creation of dynamic property ACF::$form_front is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-front.php on line 600

Deprecated: Creation of dynamic property acf_form_widget::$preview_values is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 34

Deprecated: Creation of dynamic property acf_form_widget::$preview_reference is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 35

Deprecated: Creation of dynamic property acf_form_widget::$preview_errors is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 36

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the complianz-gdpr domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-includes/functions.php on line 6170

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wpforms-lite domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-includes/functions.php on line 6170

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-includes/functions.php on line 6170

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ableneo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-includes/functions.php on line 6170

Deprecated: Creation of dynamic property acf_field_oembed::$width is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-oembed.php on line 31

Deprecated: Creation of dynamic property acf_field_oembed::$height is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-oembed.php on line 32

Deprecated: Creation of dynamic property acf_field_google_map::$default_values is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-google-map.php on line 33

Deprecated: Creation of dynamic property acf_field__group::$have_rows is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-group.php on line 31

Deprecated: Creation of dynamic property acf_field_clone::$cloning is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-clone.php on line 34

Deprecated: Creation of dynamic property acf_field_clone::$have_rows is deprecated in /data/6/a/6a361ea2-86f7-4842-bcc4-d9b941aa9bc3/studioecht.com/sub/ableneo/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-clone.php on line 35
Example of a component with styled components in defaultProps - Ableneo

Example of a component with styled components in defaultProps


Theming guidelines — Part 6 —React defaultProps Example

The previous article was about explaining why you should use components in defaultProps, now we try to create one as an example.

Improve how you style React apps —  Use components in defaultProps

Photo by Jazmin Quaynor on Unsplash

Build a simple week calendar

Let’s assume we have a task to create a calendar that will display day names in header and boxes with actual appointments below.

Everything should start with a sketch

The minimal representation would be a bunch of headers and some other elements under each header.

Sketch of the minimal representation

Example — Part #1

create new react sandbox
create a new folder called “components”
Create a new file called Calendar.js
  • install new dependencies
@emotion/core
@emotion/styled
Install dependencies
  • add the following content to the Calendar.js file
import React from "react";
import styled from "@emotion/styled";
import { css } from "@emotion/core";
const Calendar = ({ children, ...props }) => children(props);
Calendar.defaultProps = {
children: () => <h1>Calendar</h1>
};
export default Calendar;
  • click on change on Current Model View
Click on the Orange toggle
  • now you are presented with a component using render props

Example — Part #2

From the sketch you can see components you will need

  • Wrapper of the whole component
  • Column that includes Header and other Box-es with line Item-s
  • Create components
  • Add created components into children function
children: ({ Wrapper, Column, Box, Item, headers }) => (...)
  • create a skeleton from newly created components

  • Change index.js to use Calendar component
  • Copy the children part for Calendar.defaultProps and past it to index.js

Now you have a skeleton in components/Calendar.js and its implementation in index.js.

Result

Example — Part #3

  • Style components, add border and background colors for Item
  • Add some responsivity
  • Finish the look to something like this. (you can use only one color)
Skeleton with styles and colors.
Skeleton should be responsive

Example — Part #4

  • create some example data to display
  • try to change index.js to render a calendar with the example data

Result example implementation with more than can be covered

A full article explaining components in defaultProps

Improve how you style React apps —  Use components in defaultProps

👏Clap, 👂follow for more awesome 💟#Javascript, ⚛️ #React content.


Example of a component with styled components in defaultProps was originally published in ableneo Technology on Medium, where people are continuing the conversation by highlighting and responding to this story.

Related