Why A/B Testing Is Important For Your Website

Post pobrano z: Why A/B Testing Is Important For Your Website

A/B testing, which is also referred to as split testing, is the practice of using the comparison of two versions of a webpage to come to a conclusion about which one performs the best.

When you implement A/B testing for your website’s pages, you are then able to perform the validation of new design changes, test hypotheses, and invest in the improvement of your website’s conversion rate.

Improve your conversion rates with A/B Testing

It is a true statement that all websites possess a primary objective for the reason of their existence. Ecommerce sites have a desire for those visiting their sites to buy their products.

SaaS web apps have a desire for those visiting to sign up for a trial offer and then to be able to convert to a customer who will pay for the products they are offering. Websites that present media and news have a desire for those viewing their sites to click on ads or to sign up for subscriptions that they will have to pay for.

Each website that is business oriented will normally have a strong desire to see those who visit their website go on to covert to becoming more than just a visitor, but who will be someone who will eventually pay for a product or service.

It is possible to measure the performance of the A and B versions, which means measuring the rate at which those visiting the site convert to go on to become those who actually pay for a product or service.

A/B testing is not a new concept

Image source: Janna Hagan

A/B testing is not a new term that is buzzing around on the market today. Many knowledgeable and expert marketers and designers are making use of the implementation of A/B testing in their strategies relatively currently in order to be able to gain an understanding of the behavior of those visiting their sites, which will further enable them to know how to direct these visitors into the rate of conversion regarding their websites.

However, the truth of the matter is that A/B testing is not as frequently discussed as such subjects in relation to SEO, web analytics or usability. It seems that many people are not even aware of it. They do not actually comprehend what the essence of it is, how it could be beneficial to them, or how to practically implement the usage of it into their strategies.

Preparing for a test

Image source: Aaron White

The choice that you make in relation to what test you would like to implement is largely based on the goal that you desire to achieve. For example, take into consideration the fact that someone wants to increase the amount of people who sign up for something on the website.

The person then could test the length of the sign-up form, the types of fields in the form, the display of the privacy policy form, the “social proof,” etc. The goal here is to discover what is preventing people from deciding to sign up for what is offered. Is it because the length of the form is too intimidating?

Are the visitors overtly concerned about their privacy issues? Has the website done a poor job of making those visiting the site to want to sign up? Are you using retro fonts on your website instead of some more common sans serif options? It is good to know that all these things indeed can be tested by using A//B testing for the appropriate website elements.

Checklist before starting the test

Make sure to replace the element that is being tested before the page loads.

If you are about to prepare to test only one single item on a web page, (for instance, the CTA button), then you need to implement various versions of the button when using your testing tool. When the test goes live, your A/B testing tool will be able to randomly replace the button at various intervals before displaying the page to those visiting the site.

If you desire to incorporate the implementation of A/B testing in for a whole page, (for example, a theme that is green in color versus a theme that is red in color), then you have to be able to create and upload a new page for your website.

Image source: Kenil Bhavsar

Consider, for example, for a landing page that is example.com/landing.html you will need to implement variations which would be located at example.com/landing2.html. While the test is in the process of running, your tool will thus direct traffic to one of your other alternative URLs.

What to test

Image source: resumebaking.com

Headlines can be tested, as well as sub headlines. Testimonials can be important as well and worthy to test variations of them.

The text for the call to action is great to test and has shown in multiple occasions that it can make a difference. The color, shape and size of the CTA are worth testing too.

Images should be tested too. Avoid generic stock images and use realistic ones, with the subjects looking towards the CTA.

Social proof is important and should be added to a page and tested until the best version of it is found.

Image source: slack.com

Tests that are more advanced can also implemented to check on pricing, sales promotions, lengths of time associated with free trials, navigation, free or paid delivery, and so much more.

The data is priceless

Image source: Steffen

Data that is quantitative in nature indeed speaks out for itself. You and your coworkers have ideas about what will make those visiting your site to respond in a certain way in relation to the various design elements; the implementation of A/B testing will provide for the showing of two variations of the same page to those visiting your site, which will enable them to decide which one they prefer.

By continuously testing and optimizing your website, this can allow for increase in revenue, donations, leads, registrations, downloads, and content that is generated by users, all the while providing the teams associated with the website information about their visitor’s preferences and behavior, etc.

Worth the time and money

A/B testing that is done accurately can make a very big impact on your overall bottom line. The usage of controlled testing and the collection of empirical data can enable you to comprehend exactly what strategies in relation to marketing will function best for your company and product. When you realize that a certain variation performs much better than the other one, it would be ludicrous not to do this for other future promotions.

The usage of A/B testing will enable you to make the most out of your current traffic. The return on the investment for A/B testing can indeed be enormous, even when small changes are implemented on the landing page or website, which can result in great increases in leads, sales and revenue.

Testing time

Image source: Aaron White

It must be noted that A/B testing is not something that is just done overnight. It really depends on how much traffic you have, which will help you to decide if you will be conducting testing for only a few days all the way up to few weeks. It is important to only run one test at a time in order to obtain accurate results.

When a test has not been put in place long enough, skewed results are obtained due to the fact that not enough people have visited the site. Therefore, results will not be statistically accurate. Allowing a test to run for too long can also provide skewed results, because there are more variables which are beyond your control over longer periods of time.

Make sure that you are always aware of anything that could interfere with the results of your testing so that will be able to take into account any abnormalities statistically showing when going over the results of the testing that you have gathered. If you have any doubts about the information you have received, it is perfectly fine to retest.

The Ecological Impact of Browser Diversity

Post pobrano z: The Ecological Impact of Browser Diversity

Early in my career when I worked at agencies and later at Microsoft on Edge, I heard the same lament over and over: „Argh, why doesn’t Edge just run on Blink? Then I would have access to ALL THE APIs I want to use and would only have to test in one browser!”

Let me be clear: an Internet that runs only on Chrome’s engine, Blink, and its offspring, is not the paradise we like to imagine it to be.

As a Google Developer Expert who has worked on Microsoft Edge, with Firefox, and with the W3C as an Invited Expert, I have some opinions (and a number of facts) to drop on this topic. Let’s get to it.

What is a browser, even?

Let’s clear up some terminology.

Popular browsers you know today include Google Chrome, Apple Safari, Mozilla Firefox, and Microsoft Edge, but in the past we’ve also had such greats as NCSA Mosaic and Netscape Navigator. Whichever browser you use daily (I use Firefox, thanks for asking) is only an interface layer wrapped around a browser engine. All your bookmarks, the forward and backward arrows, that URL bar thingy—those aren’t the browser. Those are the browser’s interface. Often the people who build the browser’s engine never even touch the interface!

Browser engines are the things that actually read all the HTML and CSS and JavaScript that come down across the Internet, interpret them, and display a pretty picture of a web page for you. They have their own names. Chrome’s engine is Blink. Safari runs on WebKit. Firefox uses Gecko. Edge sits on top of EdgeHTML. (I like this naming convention. Good job, Edge.)

Except for Edge, all of these engines are open source, meaning anybody could grab one, wrap it in a new interface, and boom, release their own browser—maybe with a different (perhaps better) user experience—and that’s just what some browsers are! Oculus Browser, Brave, Vivaldi, Samsung Internet, Amazon’s Silk, and Opera all run on Blink. We call them “Chromium-based browsers”—Chromium is Google’s open source project from which Chrome and its engine emerged.

But what’s inside a browser engine? MOAR ENGINES! Every browser engine is comprised of several other engines:

  • A layout and rendering engine (often so tightly coupled that there’s no distinction) that calculates how the page should look and handles any paints, renders, and even animations.
  • A JavaScript engine, which is its own thing and can even run independently of the browser altogether. For instance, you can use Chrome’s V8 engine or Microsoft Edge’s Chakra to run Node on a server.

I like to compare browser engines to biological cells. Where a cell contains many organelles to perform different functions, so too do browsers. One can think of the nucleus as the rendering engine, containing the blueprints for how the page should display, and the mitochondria as the JavaScript engine, powering our everyday interactions. (Fun fact: mitochondria used to be standalone cells at one point, too, and they even carry their own DNA!)

And you know what? Another way browsers are like living things is that they evolve.

Browser evolution

Back when the first browsers came out, it was a simpler time. CSS was considered the hot new thing when it first appeared in Microsoft Internet Explorer 3 in 1996! There were far fewer JavaScript APIs and CSS specifications to implement than there are today. Over the years, browser codebases have grown to support the number of new features users and developers require to build modern web experiences. It is a delicate evolution between user needs, browser engineering effort, and specification standardization processes.

We have three major lineages of engines right now:

  • WebKit and Blink (Blink originally being a fork of WebKit) running Safari, Chrome, and Opera
  • Gecko running Firefox
  • EdgeHTML (a fork of Trident, aka MSHTML) running Microsoft Edge

Each is very different and has different strengths and weaknesses. Each could pull the Web in a different direction alone: Firefox’s engine has multithreaded processing for rendering blazing fast graphics. Edge’s engine has the least abstraction from the operating system, giving it more direct access to system resources—but making it a Windows-only browser engine as a result. And Chrome’s Blink has the most web developers testing for it. (I’ll get back to why this is a „feature” in a little bit.)

Remember all those Chromium-based browsers we talked about? Well, none of these browsers have to build their rendering engine or JavaScript engines from scratch: they just piggy-back off of Blink. And if there are new features they need? They can develop those features and keep them to themselves, or they can share those features back “upstream” to become a part of the core engine for other browsers to use. (This process is often fraught with politics and logistics—”contributing back” is easier said than done!)

It is hard to imagine any one entity justifying the hours and expense it would take to spin up a browser engine from scratch today. Even the current three engine families are evolutions of engines that were there from the very start of the Internet. They’ve evolved piecemeal alongside us, growing to meet our needs.

Right now, the vast majority of traffic on the Web is happening on Chrome, iOS Safari, or some other permutation of Blink or WebKit.

Branches, renovations, and gut jobs

Some developers would say that WebKit and Blink were forked so long ago that the two are practically completely different browser engines now, no longer able to share contributions. That may be true to a point. But while a common chimney swift and a ruby-throated hummingbird are completely different animals in comparison to each other, when compared to the other animal families, they are still very much birds. Neither’s immediate offspring are likely to manifest teeth, hands, or tails in the near future. Neither WebKit nor Blink have the processing features that Gecko and EdgeHTML have been building up to for years.

Other developers might point out that Microsoft Edge is supposedly a „complete rewrite” of Internet Explorer. But the difference between a „complete gut job” and a mere „renovation” can be a matter of perspective. EdgeHTML is a fork of Internet Explorer’s Trident engine, and it still carries much of Trident’s backlog with it.

Browser extinction

So these are the three browser engines we have: WebKit/Blink, Gecko, and EdgeHTML. We are unlikely to get any brand new bloodlines in the foreseeable future. This is it.

If we lose one of those browser engines, we lose its lineage, every permutation of that engine that would follow, and the unique takes on the Web it could allow for.

And it’s not likely to be replaced.

Imagine a planet populated only by hummingbirds, dolphins, and horses. Say all the dolphins died out. In the far, far future, hummingbirds or horses could evolve into something that could swim in the ocean like a dolphin. Indeed, ichthyosaurs in the era of dinosaurs looked much like dolphins. But that creature would be very different from a true dolphin: even ichthyosaurs never developed echolocation. We would wait a very long time (possibly forever) for a bloodline to evolve the traits we already have present in other bloodlines today. So, why is it ok to stand by or even encourage the extinction of one of these valuable, unique lineages?

We have already lost one.

We used to have four major rendering engines, but Opera halted development of its own rendering engine Presto before adopting Blink.

Three left. Spend them wisely.

By our powers combined…

Some folks feel that if a browser like Microsoft Edge ran on Blink, then Microsoft’s engineers could help build a better Blink, contributing new features upstream for all other Chromium browsers to benefit from. This sounds sensible, right?

But remember Blink was forked from WebKit. Now there are WebKit contributors and Blink contributors, and their contributions don’t port one to one. It’s not unlikely that a company like Microsoft would, much like Samsung and Occulus, want to do things with the engine differently from Google. And if those differences are not aligned, the company will work on a parallel codebase and not contribute that work upstream. We end up with a WebKit and a Blink—but without the deep differentiation that comes from having a codebase that has been growing with the Internet for decades.

It’s is a nice idea in theory. But in practice, we end up in a similar pickle—and with less „genetic variety” in our ecosystem of browser engines.

Competition is about growing, not „winning”

I’m a fan of competition. Competing with other cartoonists to make better comics and reach a larger audience got me to where I am today. (True story: got my start building websites as a cartoonist building her own community site, newsletter, and shopping cart.) I like to remind people that competition isn’t about annihilating your competitors. If you did, you’d stagnate and lose your audience: see also Internet Explorer 6.

Internet Explorer 6 was an amazing browser when it came out: performant enough to really deliver on features previous versions of Internet Explorer introduced like the DOM, data-binding, and asynchronous JavaScript. It’s rival, Netscape Navigator, couldn’t compete and crumbled into dust (only to have its engine, Gecko, rewritten from scratch—it was that small!—by the Mozilla Foundation to be reborn as Firefox later).

Thinking it had Won the Internet, Microsoft turned its attention to other fronts, and Internet Explorer didn’t advance much. When the iPhone came, Apple focused on its profitable apps marketplace and cut efforts to support Flash—the Web’s most app-like interaction platform. Apps gave content creators a way to monetize their efforts with something other than an advertising model. Advertising being Google’s bread and butter, the Big G grew concerned as the threat of a walled garden of apps only using the Internet for data plumbing loomed. Microsoft, meanwhile, was preoccupied with building its own mobile OS. So Google did two things: Android and Chrome.

Chrome promised a better, faster browsing experience. It was barebones, but Google even went all out and got famous (in my circles at least) cartoonist Scott McCloud to make a comic explaining the browser’s mission to users. With Chrome’s omnipresence on every operating system and Android phone, its dev tools modeled off Firefox’s beloved Firebug extension, and increasing involvement in specs, Chrome not only shook Internet Explorer out of its slumber, it was damn near threatening to kill off every other browser engine on the planet!

Pruning the great family tree of browsers (or collection of bushes as it were) down to a single branch smacks of fragile monoculture. Monocultures are easily disrupted by environmental and ecological challenges—by market and demographic changes. What happens when the next threat to the Web rears its head, but we don’t have Firefox’s multithreading? Or Microsoft Edge’s system integration? Will we be able to iterate fast enough without them? Or will we look to the Chrome developers to do something and pray that they have not grown stagnant as Google turned, like Microsoft did, to attend to other matters after „winning the Web.”

It is ironic that the browser Google built to keep the Web from losing to the apps model is itself monopolizing web development much the same way Internet Explorer 6 did.

It’s good to be king (of the jungle)

I promised I’d get back to „user base size as a feature.” Having the vast majority of the web development community building and testing for your platform is a major competitive advantage. First off, you’re guaranteed that most sites are going to work perfectly in your browser—you won’t have to spend so much time and effort tapping Fortune 500 sites on the shoulder about this One Weird Bug that is causing all their internal users to switch to your competitor browser and never come back. A downward spiral of fewer users leading to less developer testing leading to fewer users begins that is hard to shake.

It also makes it much easier to propose new specifications that serve your parent company’s goals (which may or may not serve the web community’s goals) and have that large community of developers build to your implementation first without having to wait for other browsers to catch up. If a smaller browser proposes a spec that no one notices and you pick it up when you need it, people will remember it as being your effort, continuing to build your mindshare whether intentionally or not.

This creates downward pressure on the competition, which simply doesn’t have or cannot use the same resources the biggest browser team has at its disposal. It’s a brutally efficient method, whether by design or accident.

Is it virtuous? At the individual contributor level, yes. Is it a vicious cycle by which companies have driven their competition to extinction by forcing them to spend limited resources to catch up? Also yes. And having legions of people building for just your platform helps.

All the awesome, well-meaning, genuinely good-hearted people involved—from the Chrome team to web developers—can throw their hands up and legitimately say, “I was just trying to build the Web forward!” while contributing to further a corporate monopoly.

Chrome has the most resources and leads the pack in building the Web forward to the point that we can’t be sure if we’re building the Web we want… or the Web Google wants.

Speculative biology

There was a time when Microsoft bailed out Apple as it was about to sink. This was not because Bill Gates and Steve Jobs were friends—no, Microsoft needed Apple to succeed so there would still be operating system competition. (No business wants to be seen as a monopoly!)

But consider, for a moment, that Apple had died. What would personal computers be like today if we’d only had Linux and Windows left standing? What would mobile computing look like if Apple hadn’t been around to work on the iPhone?

Yes, it’s easier to develop and test in only one browser. I’m sure IT professionals would have loved to only support one kind of machine. But variety creates opportunity for us as developers in the long run. Microsoft saving Apple lead to apps which challenged the Web which gave us Chrome and the myriad of APIs Google is charging ahead with. If at any point in this chain of events someone had said, „Meh, it’s so much easier if we all use the same thing,” we wouldn’t have the careers—or the world—that we have now.

Develop in more than one browser. Test in more than one browser. Use more than one browser.

You are both consumer and producer. You have a say in how the future plays out.

The post The Ecological Impact of Browser Diversity appeared first on CSS-Tricks.

How to Create an Isometric Layered Text Effect in Adobe Illustrator

Post pobrano z: How to Create an Isometric Layered Text Effect in Adobe Illustrator

Final product image
What You’ll Be Creating

In the following steps you will learn how to create an isometric layered text effect in Adobe Illustrator.

For starters, you will learn how to create a simple piece of text and how to adjust its attributes. Taking full advantage of the Appearance panel, you will learn how to add multiple layers to the text. Using a simple 3D Rotate text effect, you will learn how to add an isometric look to the text.

Finally, you will learn how to add a simple background and a subtle texture to the final design.

For more inspiration on how to adjust or improve your final text effect, you can find plenty of resources at GraphicRiver.

What You’ll Need

You’ll need the following resource in order to complete this project:

1. How to Create the First Piece of Text

Step 1

Hit Control-N to create a new document. Select Pixels from the Units drop-down menu, enter 850 in the width box and 540 in the height box, and then click that More Settings button. Select RGB for the Color Mode, set the Raster Effects to Screen (72 ppi), and then click Create Document.

Open the Info panel (Window > Info) for a live preview with the size and position of your selections. Don’t forget to set the unit of measurement to pixels from Edit > Preferences > Units. All these options will significantly increase your work speed.

new document

Step 2

Pick the Type Tool (T) and open the Character panel (Window > Type > Character). Select the Auro font and set the size to 200 px.

Click on the artboard and add your „Red” piece of text about as shown below. Make it black, for now.

type tool

Step 3

Select your text, focus on the Swatches panel (Window > Swatches), and click that [None] swatch to remove the black text color.

Move to the Appearance panel (Window > Appearance) and add a new fill using the Add New Fill button. Select that new fill and set the color to R=242 G=242 B=248.

add new fill

Step 4

Make sure that your text stays selected, focus on the Appearance panel, and add a second fill using that same Add New Fill button.

Select this new fill, set the color to R=58 G=95 B=245, and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 5 in the Copies box, and then click OK.

transform effect

Step 5

Make sure that your text stays selected and keep focusing on the Appearance panel. Add a third fill and move it in the bottom of the panel. Set its color to R=242 G=242 B=248 and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 10 in the Copies box, and then click OK.

Return to the Appearance panel, select the blue fill, and duplicate it using the Duplicate Selected Item button. Drag this new fill to the bottom of the Appearance panel and open the Transform effect applied to it. Enter 15 in the Copies box and click OK.

duplidcate selected item

Step 6

Make sure that your text stays selected and keep focusing on the Appearance panel.

Continue to duplicate the bottom fills, varying the two colors, and with every new fill increase the value in the Copies box by 5. Stop at the 20th fill. In the end, things should look like in the following image.

multiply fill

2. How to Create the Second Piece of Text

Step 1

Duplicate your piece of text. Select the copy and simply replace the „Red” with „Blue”.

duplicate text

Step 2

Select your „Blue” piece of text and focus on the Appearance panel. Select all the blue fills and simply replace that color with R=235 G=47 B=38.

red fills

Step 3

Make sure that your „Blue” piece of text is still selected and keep focusing on the Appearance panel. One by one, open the Transform effects applied to the 19 fills and drag the Move-Horizontal sliders to -0.8 px.

transform effect

3. How to Apply the 3D Isometric Effect

Step 1

Select your „Blue” piece of text and focus on the Appearance panel. Make sure that the entire piece of text is selected (simply click the „Type” piece of text from the top of the panel) and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

3D Rotate

Step 2

Select your „Red” text and focus on the Appearance panel. Make sure that the entire piece of text is selected and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

isometric

Step 3

Bring your „Red” piece of text to front (Shift-Control-]) and place it as shown below.

place text

4. How to Create the Text Shadow

Step 1

Pick the Type Tool (T) and add a second „Red” piece of text. Use the same font attributes and set its color to R=58 G=95 B=245.

blue text

Step 2

Make sure that your blue piece of text stays selected and go to Effect > Distort & Transform > Transform. Enter the attributes shown below, click OK, and go to Effect > 3D > Rotate. Enter the settings shown below and click OK.

isometric text

Step 3

Pick the Type Tool (T) and add a second „Blue” piece of text. Use the same font attributes and set its color to R=235 G=47 B=38.

red text

Step 4

Make sure that your red piece of text stays selected and go to Effect > 3D > Rotate. Enter the attributes shown below, click OK, and go to Effect > Distort & Transform > Transform. Enter the settings shown below and click OK.

isometric text

5. How to Create the Background

Step 1

Pick the Rectangle Tool (M) and create an 870 x 560 px shape. Fill this new shape with R=242 G=242 B=248, send it to back (Shift-Control-[), and make sure that it covers your entire artboard.

background

Step 2

Select your rectangle, add a copy in front (Control-C > Control-F), and bring it to front (Shift-Control-]).

Make sure that this new shape stays selected and focus on the Appearance panel. First, replace the flat color with the radial gradient shown below. Use the Gradient Tool (G) to stretch your gradient about as shown below. Lower its Opacity to 5% and change the Blending Mode to Multiply, and then go to Effect > Artistic > Film Grain. Enter the attributes shown below and click OK.

radial gradient

Congratulations! You’re Done!

Here is how it should look. I hope you’ve enjoyed this tutorial and can apply these techniques in your future projects. Don’t hesitate to share your final result in the comments section.

Feel free to adjust the final design and make it your own. You can find some great sources of inspiration at GraphicRiver, with interesting solutions to improve your design.

final product

How to Create an Isometric Layered Text Effect in Adobe Illustrator

Post pobrano z: How to Create an Isometric Layered Text Effect in Adobe Illustrator

Final product image
What You’ll Be Creating

In the following steps you will learn how to create an isometric layered text effect in Adobe Illustrator.

For starters, you will learn how to create a simple piece of text and how to adjust its attributes. Taking full advantage of the Appearance panel, you will learn how to add multiple layers to the text. Using a simple 3D Rotate text effect, you will learn how to add an isometric look to the text.

Finally, you will learn how to add a simple background and a subtle texture to the final design.

For more inspiration on how to adjust or improve your final text effect, you can find plenty of resources at GraphicRiver.

What You’ll Need

You’ll need the following resource in order to complete this project:

1. How to Create the First Piece of Text

Step 1

Hit Control-N to create a new document. Select Pixels from the Units drop-down menu, enter 850 in the width box and 540 in the height box, and then click that More Settings button. Select RGB for the Color Mode, set the Raster Effects to Screen (72 ppi), and then click Create Document.

Open the Info panel (Window > Info) for a live preview with the size and position of your selections. Don’t forget to set the unit of measurement to pixels from Edit > Preferences > Units. All these options will significantly increase your work speed.

new document

Step 2

Pick the Type Tool (T) and open the Character panel (Window > Type > Character). Select the Auro font and set the size to 200 px.

Click on the artboard and add your „Red” piece of text about as shown below. Make it black, for now.

type tool

Step 3

Select your text, focus on the Swatches panel (Window > Swatches), and click that [None] swatch to remove the black text color.

Move to the Appearance panel (Window > Appearance) and add a new fill using the Add New Fill button. Select that new fill and set the color to R=242 G=242 B=248.

add new fill

Step 4

Make sure that your text stays selected, focus on the Appearance panel, and add a second fill using that same Add New Fill button.

Select this new fill, set the color to R=58 G=95 B=245, and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 5 in the Copies box, and then click OK.

transform effect

Step 5

Make sure that your text stays selected and keep focusing on the Appearance panel. Add a third fill and move it in the bottom of the panel. Set its color to R=242 G=242 B=248 and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 10 in the Copies box, and then click OK.

Return to the Appearance panel, select the blue fill, and duplicate it using the Duplicate Selected Item button. Drag this new fill to the bottom of the Appearance panel and open the Transform effect applied to it. Enter 15 in the Copies box and click OK.

duplidcate selected item

Step 6

Make sure that your text stays selected and keep focusing on the Appearance panel.

Continue to duplicate the bottom fills, varying the two colors, and with every new fill increase the value in the Copies box by 5. Stop at the 20th fill. In the end, things should look like in the following image.

multiply fill

2. How to Create the Second Piece of Text

Step 1

Duplicate your piece of text. Select the copy and simply replace the „Red” with „Blue”.

duplicate text

Step 2

Select your „Blue” piece of text and focus on the Appearance panel. Select all the blue fills and simply replace that color with R=235 G=47 B=38.

red fills

Step 3

Make sure that your „Blue” piece of text is still selected and keep focusing on the Appearance panel. One by one, open the Transform effects applied to the 19 fills and drag the Move-Horizontal sliders to -0.8 px.

transform effect

3. How to Apply the 3D Isometric Effect

Step 1

Select your „Blue” piece of text and focus on the Appearance panel. Make sure that the entire piece of text is selected (simply click the „Type” piece of text from the top of the panel) and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

3D Rotate

Step 2

Select your „Red” text and focus on the Appearance panel. Make sure that the entire piece of text is selected and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

isometric

Step 3

Bring your „Red” piece of text to front (Shift-Control-]) and place it as shown below.

place text

4. How to Create the Text Shadow

Step 1

Pick the Type Tool (T) and add a second „Red” piece of text. Use the same font attributes and set its color to R=58 G=95 B=245.

blue text

Step 2

Make sure that your blue piece of text stays selected and go to Effect > Distort & Transform > Transform. Enter the attributes shown below, click OK, and go to Effect > 3D > Rotate. Enter the settings shown below and click OK.

isometric text

Step 3

Pick the Type Tool (T) and add a second „Blue” piece of text. Use the same font attributes and set its color to R=235 G=47 B=38.

red text

Step 4

Make sure that your red piece of text stays selected and go to Effect > 3D > Rotate. Enter the attributes shown below, click OK, and go to Effect > Distort & Transform > Transform. Enter the settings shown below and click OK.

isometric text

5. How to Create the Background

Step 1

Pick the Rectangle Tool (M) and create an 870 x 560 px shape. Fill this new shape with R=242 G=242 B=248, send it to back (Shift-Control-[), and make sure that it covers your entire artboard.

background

Step 2

Select your rectangle, add a copy in front (Control-C > Control-F), and bring it to front (Shift-Control-]).

Make sure that this new shape stays selected and focus on the Appearance panel. First, replace the flat color with the radial gradient shown below. Use the Gradient Tool (G) to stretch your gradient about as shown below. Lower its Opacity to 5% and change the Blending Mode to Multiply, and then go to Effect > Artistic > Film Grain. Enter the attributes shown below and click OK.

radial gradient

Congratulations! You’re Done!

Here is how it should look. I hope you’ve enjoyed this tutorial and can apply these techniques in your future projects. Don’t hesitate to share your final result in the comments section.

Feel free to adjust the final design and make it your own. You can find some great sources of inspiration at GraphicRiver, with interesting solutions to improve your design.

final product

How to Create an Isometric Layered Text Effect in Adobe Illustrator

Post pobrano z: How to Create an Isometric Layered Text Effect in Adobe Illustrator

Final product image
What You’ll Be Creating

In the following steps you will learn how to create an isometric layered text effect in Adobe Illustrator.

For starters, you will learn how to create a simple piece of text and how to adjust its attributes. Taking full advantage of the Appearance panel, you will learn how to add multiple layers to the text. Using a simple 3D Rotate text effect, you will learn how to add an isometric look to the text.

Finally, you will learn how to add a simple background and a subtle texture to the final design.

For more inspiration on how to adjust or improve your final text effect, you can find plenty of resources at GraphicRiver.

What You’ll Need

You’ll need the following resource in order to complete this project:

1. How to Create the First Piece of Text

Step 1

Hit Control-N to create a new document. Select Pixels from the Units drop-down menu, enter 850 in the width box and 540 in the height box, and then click that More Settings button. Select RGB for the Color Mode, set the Raster Effects to Screen (72 ppi), and then click Create Document.

Open the Info panel (Window > Info) for a live preview with the size and position of your selections. Don’t forget to set the unit of measurement to pixels from Edit > Preferences > Units. All these options will significantly increase your work speed.

new document

Step 2

Pick the Type Tool (T) and open the Character panel (Window > Type > Character). Select the Auro font and set the size to 200 px.

Click on the artboard and add your „Red” piece of text about as shown below. Make it black, for now.

type tool

Step 3

Select your text, focus on the Swatches panel (Window > Swatches), and click that [None] swatch to remove the black text color.

Move to the Appearance panel (Window > Appearance) and add a new fill using the Add New Fill button. Select that new fill and set the color to R=242 G=242 B=248.

add new fill

Step 4

Make sure that your text stays selected, focus on the Appearance panel, and add a second fill using that same Add New Fill button.

Select this new fill, set the color to R=58 G=95 B=245, and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 5 in the Copies box, and then click OK.

transform effect

Step 5

Make sure that your text stays selected and keep focusing on the Appearance panel. Add a third fill and move it in the bottom of the panel. Set its color to R=242 G=242 B=248 and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 10 in the Copies box, and then click OK.

Return to the Appearance panel, select the blue fill, and duplicate it using the Duplicate Selected Item button. Drag this new fill to the bottom of the Appearance panel and open the Transform effect applied to it. Enter 15 in the Copies box and click OK.

duplidcate selected item

Step 6

Make sure that your text stays selected and keep focusing on the Appearance panel.

Continue to duplicate the bottom fills, varying the two colors, and with every new fill increase the value in the Copies box by 5. Stop at the 20th fill. In the end, things should look like in the following image.

multiply fill

2. How to Create the Second Piece of Text

Step 1

Duplicate your piece of text. Select the copy and simply replace the „Red” with „Blue”.

duplicate text

Step 2

Select your „Blue” piece of text and focus on the Appearance panel. Select all the blue fills and simply replace that color with R=235 G=47 B=38.

red fills

Step 3

Make sure that your „Blue” piece of text is still selected and keep focusing on the Appearance panel. One by one, open the Transform effects applied to the 19 fills and drag the Move-Horizontal sliders to -0.8 px.

transform effect

3. How to Apply the 3D Isometric Effect

Step 1

Select your „Blue” piece of text and focus on the Appearance panel. Make sure that the entire piece of text is selected (simply click the „Type” piece of text from the top of the panel) and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

3D Rotate

Step 2

Select your „Red” text and focus on the Appearance panel. Make sure that the entire piece of text is selected and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

isometric

Step 3

Bring your „Red” piece of text to front (Shift-Control-]) and place it as shown below.

place text

4. How to Create the Text Shadow

Step 1

Pick the Type Tool (T) and add a second „Red” piece of text. Use the same font attributes and set its color to R=58 G=95 B=245.

blue text

Step 2

Make sure that your blue piece of text stays selected and go to Effect > Distort & Transform > Transform. Enter the attributes shown below, click OK, and go to Effect > 3D > Rotate. Enter the settings shown below and click OK.

isometric text

Step 3

Pick the Type Tool (T) and add a second „Blue” piece of text. Use the same font attributes and set its color to R=235 G=47 B=38.

red text

Step 4

Make sure that your red piece of text stays selected and go to Effect > 3D > Rotate. Enter the attributes shown below, click OK, and go to Effect > Distort & Transform > Transform. Enter the settings shown below and click OK.

isometric text

5. How to Create the Background

Step 1

Pick the Rectangle Tool (M) and create an 870 x 560 px shape. Fill this new shape with R=242 G=242 B=248, send it to back (Shift-Control-[), and make sure that it covers your entire artboard.

background

Step 2

Select your rectangle, add a copy in front (Control-C > Control-F), and bring it to front (Shift-Control-]).

Make sure that this new shape stays selected and focus on the Appearance panel. First, replace the flat color with the radial gradient shown below. Use the Gradient Tool (G) to stretch your gradient about as shown below. Lower its Opacity to 5% and change the Blending Mode to Multiply, and then go to Effect > Artistic > Film Grain. Enter the attributes shown below and click OK.

radial gradient

Congratulations! You’re Done!

Here is how it should look. I hope you’ve enjoyed this tutorial and can apply these techniques in your future projects. Don’t hesitate to share your final result in the comments section.

Feel free to adjust the final design and make it your own. You can find some great sources of inspiration at GraphicRiver, with interesting solutions to improve your design.

final product

How to Create an Isometric Layered Text Effect in Adobe Illustrator

Post pobrano z: How to Create an Isometric Layered Text Effect in Adobe Illustrator

Final product image
What You’ll Be Creating

In the following steps you will learn how to create an isometric layered text effect in Adobe Illustrator.

For starters, you will learn how to create a simple piece of text and how to adjust its attributes. Taking full advantage of the Appearance panel, you will learn how to add multiple layers to the text. Using a simple 3D Rotate text effect, you will learn how to add an isometric look to the text.

Finally, you will learn how to add a simple background and a subtle texture to the final design.

For more inspiration on how to adjust or improve your final text effect, you can find plenty of resources at GraphicRiver.

What You’ll Need

You’ll need the following resource in order to complete this project:

1. How to Create the First Piece of Text

Step 1

Hit Control-N to create a new document. Select Pixels from the Units drop-down menu, enter 850 in the width box and 540 in the height box, and then click that More Settings button. Select RGB for the Color Mode, set the Raster Effects to Screen (72 ppi), and then click Create Document.

Open the Info panel (Window > Info) for a live preview with the size and position of your selections. Don’t forget to set the unit of measurement to pixels from Edit > Preferences > Units. All these options will significantly increase your work speed.

new document

Step 2

Pick the Type Tool (T) and open the Character panel (Window > Type > Character). Select the Auro font and set the size to 200 px.

Click on the artboard and add your „Red” piece of text about as shown below. Make it black, for now.

type tool

Step 3

Select your text, focus on the Swatches panel (Window > Swatches), and click that [None] swatch to remove the black text color.

Move to the Appearance panel (Window > Appearance) and add a new fill using the Add New Fill button. Select that new fill and set the color to R=242 G=242 B=248.

add new fill

Step 4

Make sure that your text stays selected, focus on the Appearance panel, and add a second fill using that same Add New Fill button.

Select this new fill, set the color to R=58 G=95 B=245, and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 5 in the Copies box, and then click OK.

transform effect

Step 5

Make sure that your text stays selected and keep focusing on the Appearance panel. Add a third fill and move it in the bottom of the panel. Set its color to R=242 G=242 B=248 and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 10 in the Copies box, and then click OK.

Return to the Appearance panel, select the blue fill, and duplicate it using the Duplicate Selected Item button. Drag this new fill to the bottom of the Appearance panel and open the Transform effect applied to it. Enter 15 in the Copies box and click OK.

duplidcate selected item

Step 6

Make sure that your text stays selected and keep focusing on the Appearance panel.

Continue to duplicate the bottom fills, varying the two colors, and with every new fill increase the value in the Copies box by 5. Stop at the 20th fill. In the end, things should look like in the following image.

multiply fill

2. How to Create the Second Piece of Text

Step 1

Duplicate your piece of text. Select the copy and simply replace the „Red” with „Blue”.

duplicate text

Step 2

Select your „Blue” piece of text and focus on the Appearance panel. Select all the blue fills and simply replace that color with R=235 G=47 B=38.

red fills

Step 3

Make sure that your „Blue” piece of text is still selected and keep focusing on the Appearance panel. One by one, open the Transform effects applied to the 19 fills and drag the Move-Horizontal sliders to -0.8 px.

transform effect

3. How to Apply the 3D Isometric Effect

Step 1

Select your „Blue” piece of text and focus on the Appearance panel. Make sure that the entire piece of text is selected (simply click the „Type” piece of text from the top of the panel) and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

3D Rotate

Step 2

Select your „Red” text and focus on the Appearance panel. Make sure that the entire piece of text is selected and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

isometric

Step 3

Bring your „Red” piece of text to front (Shift-Control-]) and place it as shown below.

place text

4. How to Create the Text Shadow

Step 1

Pick the Type Tool (T) and add a second „Red” piece of text. Use the same font attributes and set its color to R=58 G=95 B=245.

blue text

Step 2

Make sure that your blue piece of text stays selected and go to Effect > Distort & Transform > Transform. Enter the attributes shown below, click OK, and go to Effect > 3D > Rotate. Enter the settings shown below and click OK.

isometric text

Step 3

Pick the Type Tool (T) and add a second „Blue” piece of text. Use the same font attributes and set its color to R=235 G=47 B=38.

red text

Step 4

Make sure that your red piece of text stays selected and go to Effect > 3D > Rotate. Enter the attributes shown below, click OK, and go to Effect > Distort & Transform > Transform. Enter the settings shown below and click OK.

isometric text

5. How to Create the Background

Step 1

Pick the Rectangle Tool (M) and create an 870 x 560 px shape. Fill this new shape with R=242 G=242 B=248, send it to back (Shift-Control-[), and make sure that it covers your entire artboard.

background

Step 2

Select your rectangle, add a copy in front (Control-C > Control-F), and bring it to front (Shift-Control-]).

Make sure that this new shape stays selected and focus on the Appearance panel. First, replace the flat color with the radial gradient shown below. Use the Gradient Tool (G) to stretch your gradient about as shown below. Lower its Opacity to 5% and change the Blending Mode to Multiply, and then go to Effect > Artistic > Film Grain. Enter the attributes shown below and click OK.

radial gradient

Congratulations! You’re Done!

Here is how it should look. I hope you’ve enjoyed this tutorial and can apply these techniques in your future projects. Don’t hesitate to share your final result in the comments section.

Feel free to adjust the final design and make it your own. You can find some great sources of inspiration at GraphicRiver, with interesting solutions to improve your design.

final product

How to Create an Isometric Layered Text Effect in Adobe Illustrator

Post pobrano z: How to Create an Isometric Layered Text Effect in Adobe Illustrator

Final product image
What You’ll Be Creating

In the following steps you will learn how to create an isometric layered text effect in Adobe Illustrator.

For starters, you will learn how to create a simple piece of text and how to adjust its attributes. Taking full advantage of the Appearance panel, you will learn how to add multiple layers to the text. Using a simple 3D Rotate text effect, you will learn how to add an isometric look to the text.

Finally, you will learn how to add a simple background and a subtle texture to the final design.

For more inspiration on how to adjust or improve your final text effect, you can find plenty of resources at GraphicRiver.

What You’ll Need

You’ll need the following resource in order to complete this project:

1. How to Create the First Piece of Text

Step 1

Hit Control-N to create a new document. Select Pixels from the Units drop-down menu, enter 850 in the width box and 540 in the height box, and then click that More Settings button. Select RGB for the Color Mode, set the Raster Effects to Screen (72 ppi), and then click Create Document.

Open the Info panel (Window > Info) for a live preview with the size and position of your selections. Don’t forget to set the unit of measurement to pixels from Edit > Preferences > Units. All these options will significantly increase your work speed.

new document

Step 2

Pick the Type Tool (T) and open the Character panel (Window > Type > Character). Select the Auro font and set the size to 200 px.

Click on the artboard and add your „Red” piece of text about as shown below. Make it black, for now.

type tool

Step 3

Select your text, focus on the Swatches panel (Window > Swatches), and click that [None] swatch to remove the black text color.

Move to the Appearance panel (Window > Appearance) and add a new fill using the Add New Fill button. Select that new fill and set the color to R=242 G=242 B=248.

add new fill

Step 4

Make sure that your text stays selected, focus on the Appearance panel, and add a second fill using that same Add New Fill button.

Select this new fill, set the color to R=58 G=95 B=245, and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 5 in the Copies box, and then click OK.

transform effect

Step 5

Make sure that your text stays selected and keep focusing on the Appearance panel. Add a third fill and move it in the bottom of the panel. Set its color to R=242 G=242 B=248 and go to Effect > Distort & Transform > Transform. Drag the Move-Horizontal slider to 0.8 px and the Move-Vertical slider to -0.8 px, enter 10 in the Copies box, and then click OK.

Return to the Appearance panel, select the blue fill, and duplicate it using the Duplicate Selected Item button. Drag this new fill to the bottom of the Appearance panel and open the Transform effect applied to it. Enter 15 in the Copies box and click OK.

duplidcate selected item

Step 6

Make sure that your text stays selected and keep focusing on the Appearance panel.

Continue to duplicate the bottom fills, varying the two colors, and with every new fill increase the value in the Copies box by 5. Stop at the 20th fill. In the end, things should look like in the following image.

multiply fill

2. How to Create the Second Piece of Text

Step 1

Duplicate your piece of text. Select the copy and simply replace the „Red” with „Blue”.

duplicate text

Step 2

Select your „Blue” piece of text and focus on the Appearance panel. Select all the blue fills and simply replace that color with R=235 G=47 B=38.

red fills

Step 3

Make sure that your „Blue” piece of text is still selected and keep focusing on the Appearance panel. One by one, open the Transform effects applied to the 19 fills and drag the Move-Horizontal sliders to -0.8 px.

transform effect

3. How to Apply the 3D Isometric Effect

Step 1

Select your „Blue” piece of text and focus on the Appearance panel. Make sure that the entire piece of text is selected (simply click the „Type” piece of text from the top of the panel) and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

3D Rotate

Step 2

Select your „Red” text and focus on the Appearance panel. Make sure that the entire piece of text is selected and go to Effect > 3D > Rotate. Enter the attributes shown below and click OK.

isometric

Step 3

Bring your „Red” piece of text to front (Shift-Control-]) and place it as shown below.

place text

4. How to Create the Text Shadow

Step 1

Pick the Type Tool (T) and add a second „Red” piece of text. Use the same font attributes and set its color to R=58 G=95 B=245.

blue text

Step 2

Make sure that your blue piece of text stays selected and go to Effect > Distort & Transform > Transform. Enter the attributes shown below, click OK, and go to Effect > 3D > Rotate. Enter the settings shown below and click OK.

isometric text

Step 3

Pick the Type Tool (T) and add a second „Blue” piece of text. Use the same font attributes and set its color to R=235 G=47 B=38.

red text

Step 4

Make sure that your red piece of text stays selected and go to Effect > 3D > Rotate. Enter the attributes shown below, click OK, and go to Effect > Distort & Transform > Transform. Enter the settings shown below and click OK.

isometric text

5. How to Create the Background

Step 1

Pick the Rectangle Tool (M) and create an 870 x 560 px shape. Fill this new shape with R=242 G=242 B=248, send it to back (Shift-Control-[), and make sure that it covers your entire artboard.

background

Step 2

Select your rectangle, add a copy in front (Control-C > Control-F), and bring it to front (Shift-Control-]).

Make sure that this new shape stays selected and focus on the Appearance panel. First, replace the flat color with the radial gradient shown below. Use the Gradient Tool (G) to stretch your gradient about as shown below. Lower its Opacity to 5% and change the Blending Mode to Multiply, and then go to Effect > Artistic > Film Grain. Enter the attributes shown below and click OK.

radial gradient

Congratulations! You’re Done!

Here is how it should look. I hope you’ve enjoyed this tutorial and can apply these techniques in your future projects. Don’t hesitate to share your final result in the comments section.

Feel free to adjust the final design and make it your own. You can find some great sources of inspiration at GraphicRiver, with interesting solutions to improve your design.

final product

JAMstack_conf

Post pobrano z: JAMstack_conf

I love a good conference that exists because there is a rising tide in technology. JAMstack_conf:

Static site generators, serverless architectures, and powerful APIs are giving front-end teams fullstack capabilities — without the pain of owning infrastructure. It’s a new approach called the JAMstack.

I’ll be speaking at it! I’ve been pretty interested in all this and trying to learn and document as much as I can.

Save $100 with csstricks100.

Direct Link to ArticlePermalink

The post JAMstack_conf appeared first on CSS-Tricks.

Props and PropTypes in React

Post pobrano z: Props and PropTypes in React

React encourages developers to build by breaking a UI up into components. This means there will always be a need to pass data from one component to another — more specifically, from parent to child component — since we’re stitching them together and they rely on one another.

React calls the data passed between components props and we’re going to look into those in great detail. And, since we’re talking about props, any post on the topic would be incomplete without looking at PropTypes because they ensure that components are passing the right data needed for the job.

With that, let’s unpack these essential but loaded terms together.

Props: The data being passed around

Basically, props are what make React the tool that it is. React was designed to break things down into pieces that are served when they are needed. Props are defining characteristics stored by those pieces and they are accessed and sent when they’re requested. The result is a screen that renders only what it needs and nothing more, speeding up page loads and boosting overall performance.

These data can come in different forms: namely, strings, array and functions. The ability to pass data between components, so let’s break down specifically how to access and pass data.

Passing and accessing props

Let’s say we are working on an application that shows a list of interesting demos pulled from CodePen:

See the Pen Props Pen by Kingsley Silas Chijioke (@kinsomicrote) on CodePen.

We can illustrate the app as a collection of components:

The list of pens is going to require data, notably the title, URL and author for each demo that the app displays. We can construct that data like so:

const pensList = [
  {
    title: "Elastic Input[Google Chrome]",
    url: "https://codepen.io/andreasstorm/pen/JBGWBa",
    author: "Andreas Storm"
  },
  {
    title: "Phenomenon instances!",
    url: "https://codepen.io/cvaneenige/pen/ajNjaN",
    author: "Colin van Eenige"
  },
  {
    title: "cpc-forms experiment with css variables",
    url: "https://codepen.io/terabaud/pen/YjwYKv",
    author: "Lea Rosema"
  },
  {
    title: "Nuotron Logo Animation with Hover Effect",
    url: "https://codepen.io/YahiaRefaiea/pen/YjyZLm",
    author: "Yahia Refaiea"
  }
];

The App component will pull the data. Here’s the basic structure for that component:

const App = () => {
  return (
    <div>
      <PenList pens={pensList} />
    </div>
  );
}

We are passing an array of pens as a prop to the PenList (which we’ll create in just a bit). The parent component (PenList) accesses the data (penList), which gets passed as pens props to the child component (Pen).

const PenList = props => {
  return (
    <React.Fragment>
      <h2>Interesting Pens on CodePen</h2>
      <ul>
        {props.pens.map(pen => {
          return (
            <li key={pen.url}>
              <Pen {...pen} />
            </li>
          );
        })}
      </ul>
    </React.Fragment>
  );
};

The PenList component loops through the pens props (props.pens) to return each item as a Pen component. If this was a class component, we would prefix the pens props with this, like this:

class PenList extends React.Component {
  render() {
    return (
      <React.Fragment>
        <h2>Interesting Pens on CodePen</h2>
        <ul>
          {
            this.props.pens.map(pen => {
              return (
                <li key={pen.url}>
                  <Pen {...pen} />
                </li>
              )
            })
          }
        </ul>
      </React.Fragment>
    )
  }
}

The next thing to note is the use of key in the example. A key is a unique identifier we can assign to each item in our list to make sure we can distinguish between items. In this case, we’re mapping the key to the URL of each pen. There’s no chance of two items being the same, so it’s a good piece of data to use for this purpose.

The remaining properties are passed as props to the Pen component. Here’s the Pen component making use of those props:

const Pen = props => {
  return (
    <div>
      <p>
        [{props.title}]
      </p>
      <p>Made by: {props.author}</p>
    </div>
  );
};

Note that we are constructing the Pen component (const Pen) rather than defining it as a class (class PenList) like we did for the PenList component. As such, we can access the values using props. That’s a handy little shorthand we can use instead of re-mapping Pen to the data. The parent already has it, so let’s just pass it along!

Passing functions using props

We just looked at passing an array of data as props from one component to another, but what if we’re working with functions instead? React allows us to pass functions between components, but it’s quite technical. Still, it’s something you’d want to do for specific use cases and worth us looking into.

Let’s use a simple example, say an app that allows you to create a list of tasks. You know, a to-do list, like for chores, projects or what have you. In this app, the list of tasks is contained in the App component, which is the parent component. The Todo component will be the child in this scenario, and its sole job will be to list each task that gets created.

In true to-do list form, we don’t just want to create tasks, but be able to remove them once a task has been created. Since the to-do list is contained in the App component, we have to be able to identify the specific item the user wants to remove from the list by obtaining the id and then remove the item in the App component.

Sound complex? Here’s what we’re going for:

See the Pen Props Pen 2 by Kingsley Silas Chijioke (@kinsomicrote) on CodePen.

Broken down into code:

let todoCounter = 1;

class App extends React.Component {
  state = {
    list: [],
    item: ""
  };

  handleInputChange = event => {
    this.setState({ item: event.target.value });
  };

  handleSubmit = event => {
    event.preventDefault();
    const item = {
      id: todoCounter++,
      value: this.state.item.slice()
    };
    this.setState({
      list: this.state.list.concat(item),
      item: ""
    });
  };

  handleRemove = id => {
    this.setState({
      list: this.state.list.filter(c => c.id !== id)
    });
  };

  render() {
    return (
      <React.Fragment>
        <h2>Add Todo</h2>
        <div>
          <input
            type="text"
            value={this.state.item}
            onChange={this.handleInputChange}
          />
        </div>
        <div>
          <button type="submit" onClick={this.handleSubmit}>
            Add
          </button>
        </div>
        <div>
          <h3>Lists</h3>
          <ul>
            {this.state.list.map(item => {
              return (
                <li key={item.id}>
                  <Todo {...item} removeTodo={this.handleRemove} />
                </li>
              );
            })}
          </ul>
        </div>
      </React.Fragment>
    );
  }
}

Notice that we defined todoCounter at the top and set it to 1. We created this so we can have unique keys for the to-do items just like we did when we used URLs for the list of pens in our previous example.

The method for deleting tasks is created in the App component. In the render() function, we pass the to-do properties as props to the Todo component. We also pass the handleRemove() function as a prop named removeTodo(). We will use this in the Todo component which looks like this.

class Todo extends React.Component {
  deleteTodo = id => {
    this.props.removeTodo(id);
  };
  render() {
    return (
      <div>
        {this.props.value}
        <button onClick={() => this.deleteTodo(this.props.id)}>X</button>
      </div>
    );
  }
}

We have to pass the id of the to-do item to removeTodo() in the Todo component because we cannot update the state of the App component without it. This is essentially how we are able to pass a function between components using props — pretty similar to how we did it with an array, the difference being we’re passing functionality around instead of raw data.

PropTypes

PropTypes ensure that the right type of props is passed to a component — and, conversely, that the receiving component is receiving the right type of props.

We can think about them like a football quarterback passing the ball to a receiver. The quarterback only wants his players to receive the ball. And, for that matter, the quarterback wants the receiver to catch a ball — not a cat, pickle or taxi. PropTypes would ensure that the correct object (a ball) is being passed and that it is passed to the correct receiver (player on the team).

(If only football had PropTypes in real life!)

To make use of PropTypes, you have to add the package as a dependency to your application by running yarn add prop-types in the command line.

We can use PropTypes in our app that displays interesting pens. Here is how we will use it for the Pen component:

Pen.propTypes = {
  title: PropTypes.string,
  url: PropTypes.string,
  author: PropTypes.string
};

We’re declaring that the props for title, url and author should be strings. Not numbers. Not functions. Strings and strings alone.

If we happened to the props of author to a number instead of a string like this:

author: PropTypes.number

…we will get an error:

Warning: Failed prop type: Invalid prop `author` of type `string` supplied to `Pen`, expected `number`.

So, PropTypes are useful in catching bugs. We can also enforce passing props by using isRequired:

Pen.propTypes = {
  title: PropTypes.string.isRequired,
  url: PropTypes.string.isRequired,
  author: PropTypes.string.isRequired
};

The basic data types you will need include string, number, boolean, function, etc.

Person.propTypes = {
  email: PropTypes.string,
  age: PropTypes.number,
  availability: PropTypes.bool,
  handleSubmit: PropTypes.func
}

There are more types available and tons of documentation on them.

In cases where a prop is optional (i.e. not using isRequired), you can set a default value to make sure something gets passed:

Developer.defaultProps = {
  language: 'JavaScript' 
}

With this, the language prop will always have a value when it used — even if one isn’t provided.

Wrap Up

Well, that’s a broad look at props in React. It’s pretty much a guarantee that you will use both props and propTypes in a React application. Hopefully this post shows just how important they are to React as a whole because, without them, we have nothing to pass between components when interactions happen. They’re very much a core part of the component-driven and state management architecture that React is designed around.

And propTypes are an added bonus — like a built-in quality assurance checker for catching bugs and letting us know about them. Nice to know that they’ve got our back as we work.

The post Props and PropTypes in React appeared first on CSS-Tricks.

Agregator najlepszych postów o designie, webdesignie, cssie i Internecie