Displaying the Current Step with CSS Counters

Say you have five buttons. Each button is a step. If you click on the fourth button, you’re on step 4 of 5, and you want to display that.

This kind of counting and displaying could be hard-coded, but that’s no fun. JavaScript could do this job as well. But CSS? Hmmmm. Can it? CSS has counters, so we can certainly count the number of buttons. But how do we calculate only up to a certain button? Turns out it can be done.

Thanks to Jan Enning for emailing in about this trick, it’s very clever!

HTML

It doesn’t have to be buttons; it just needs to be some sibling elements we can count. But we’ll go ahead and use buttons here:

<div class="steps">

  <button class="active">Shop</button>
  <button>Cart</button>
  <button>Shipping</button>
  <button>Checkout</button>
  <button>Thank You</button>

  <div class="message"></div>

</div>

The empty .message div there will be where we output our step messaging with CSS content.

CSS

The trick is that we’re actually going to use three counters:

  1. A total count of all the buttons
  2. A count of the current step
  3. A count of how many remaining steps are after the current step
.steps {
  counter-reset: 
    currentStep 0 
    remainder 0 
    totalStep 0;
}

Now let’s actually do the counting. To count all buttons is straightforward:

button {
  counter-increment: totalStep;
}

Next, we need another thing to count that will also count the buttons. We can use a pseudo-element that’s only purpose is to count buttons:

button::before {
  content: "";
  counter-increment: currentStep;
}

The trick is to stop counting that pseudo-element on all the elements after the active element. If we’re using an .active class that looks like this:

button.active ~ button::before {
  /* prevents currentStep from being incremented! */
  counter-increment: remainder;
}

We’re counting the remainder there, which might also be useful, but because we’re only incrementing the remainder, that means we’re not counting the currentStep counter. Fancy, fancy.

Then we can use the counters to output our messaging:

message::before {
  content: "Step: " counter(currentStep) " / " counter(totalStep);
}

Here it is!

There is a little JavaScript there so you can play with moving the active state on the button, but the counting and messaging is all CSS.

The post Displaying the Current Step with CSS Counters appeared first on CSS-Tricks.

New Gatsby Source WordPress Plugin Now in Beta

Gatsby announced its new source plugin (v4) for WordPress is now in beta. The plugin has been completely revamped to improve headless WordPress setups where Gatsby powers the frontend. It also integrates with Gatsby Cloud to provide real-time previews and incremental builds.

The Gatsby team has had a long journey towards creating an integration for WordPress sites that would satisfy more complex use cases. There are currently three different avenues for using Gatsby with WordPress, each with different benefits and drawbacks:

  • Gatsby Source WordPress + WP REST API
  • Gatsby Source GraphQL + WPGraphQL
  • Gatsby Source WordPress (v4) + WPGraphQL

The first approach relies on the WP REST API to fetch all data (posts, terms, media, etc) and cache the data in Gatsby’s node cache. The second method allows developers to write GraphQL queries to fetch data from the Gatsby cache and render that data in templates.

According to Gatsby engineer and WPGraphQL creator Jason Bahl, the first two approaches are only adequate for basic use cases.

“When you start adding more advanced functionality, such as Advanced Custom Fields Flex Fields, the WP REST API starts to fall apart and become very difficult to use in a decoupled way,” Bahl said. “The WP REST API has a Schema that can allow plugins and themes to extend the WP REST API and declare what type of data any given endpoint will expose. This is helpful for decoupled applications to know ahead of time what kind of data to expect.

“The problem is that plugins and themes can extend the WP REST API without making use of the Schema, or by simply defining field types in the Schema as `object` or `array` Types. This means there’s no easy way for decoupled applications, including Gatsby, to know what to expect from those fields. Gatsby relies on consistent data, and the WP REST API isn’t consistent. The shape of the data returned from endpoints (especially when plugins extend the REST API) is unpredictable and that is problematic for decoupled applications.”

WPGraphQL was created as an alternative to the WP REST API, addressing many of these pain points with its enforced Schema. This benefits decoupled tools like Gatsby because they can introspect the Schema to determine what data is available before requesting any.

“So even cases such as Advanced Custom Fields Flex Fields, where the data being returned could be one of many possible Flex Field Layouts, Gatsby can still know what the possible data is before asking for the data,” Bahl said. “The enforced Schema of WPGraphQL allows decoupled tools to ship with confidence and eliminates entire classes of bugs.”

The Gatsby Source GraphQL + WPGraphQL approach has some improvements over using the WP REST API but was limited in that it doesn’t cache data to the Gatsby node cache. This prevents WordPress sites from being able to utilize Gatsby’s cloud-based commercial offerings for previews and incremental builds. Bahl explained how the new Gatsby Source WordPress plugin (v4) + WPGraphQL is the “best of both worlds:”

It uses WPGraphQL on the WordPress server to expose WordPress data in a Typed GraphQL Schema. Gatsby Source WordPress v4 uses GraphQL Introspection to read the Schema from the WordPress site and builds a nearly identical Schema in Gatsby. It then fetches data using WPGraphQL and caches the data in Gatsby. Users then use GraphQL to interact with the Gatsby cache and get data to render in Components in their Gatsby site.

The new integration gives content creators the ability to click “preview” to see their changes live in the Gatsby-powered site. Publishing no longer requires a full site rebuild. It will simply push out the changes to the affected pages. Changes will be live in seconds, similar to how users expect WordPress to work without the headless integration. The new plugin, combined with Gatsby Cloud, provide a better marriage of the content creation experience with Gatsby’s React + GraphQL developer experience, while delivering fast static pages on the frontend.

If you want to test the beta of the new Gatsby Source WordPress plugin, you can find it (and its dependencies) on GitHub. The WPGraphQL and WPGatsby plugins are also required.

What Are The Ways To Capture User Feedback in React Native Application?

There’s nothing like receiving real feedback from your users. But the question is how to capture that feedback. Here we will discuss everything about how you should prompt them, when you should prompt them, and what tools can be used to capture the user’s feedback in react native application. 

Let’s have a look at some of the bad ways or bad times when applications ask for a feedback or a review:

4 Tips for Improving Code Readability

Most readers will never read an entire article. More specifically, most readers will never make it more than 75 words into an article, and they will make that decision in seconds. According to a 2014 Time Magazine article, 55% of readers on the internet will stop reading a website after just 15 seconds. For the average adult—who reads about 300 words a minute—that is only about 75 words. For a 1,500 word article, that is only about 4% of this article—less than this first paragraph.

Bearing that in mind, many are likely to scan an article, rather than read any sizable portion of the text, before making the decision to continue reading. In software articles, one of the most obvious parts of the article that can aid or dissuade in keeping the reader's attention is code snippets. Concise, well-formatted code snippets can go a long way in helping a reader understand the purpose of the article, while simultaneously signaling to the reader that we, the author, have taken the effort to ensure that code is readable.

Two Ways to Dockerize Spring Boot Applications

Microservices are often built with the Spring Boot framework and deployed with Docker. This paper looks at two common options for Dockerizing Spring Boot applications. Throughout we will use a simple REST application as a running example.

We will use Spring Tool Suite to build the application, though neither the IDE nor the application matter all that much, as long as we have the pom file. We will assume that the reader has minimal knowledge of Docker, though as we shall see one of the options we will discuss, requires no knowledge of Docker. Here then is the REST controller:

All About Maps — Episode 1: Showing Routes From GPX Files on Maps

All About Maps

Let's talk about maps. I started an open-source project called All About Maps (https://github.com/ulusoyca/AllAboutMaps). In this project, I aim to demonstrate how we can implement the same map related use cases with different map providers in one codebase. We will use Mapbox Maps, Google Maps, and Huawei HMS Map Kit. This project uses the following libraries and patterns:

  • MVVM pattern with Android Jetpack Libraries

Anti-Virus and 0-Day Threat Protection for Java Web Applications

Web APIs and applications are increasingly becoming a target. Gartner predicts that by 2022, the #1 attack vector for enterprise applications will be the API. Not only can end-users upload viruses, but attackers can craft specialized attack malware and upload this content through your public web application. Once uploaded, these threats can move through your systems, being stored in cloud storage or databases, and eventually can get executed.

Consider an example: an insurance company allows its users to upload PDFs as part of the claims process. An attacker creates a custom executable and uploads that into the claims UI. Since it has the right file extension (.PDF), the system accepts it and stores it into its database. Because it is a new, 0-day threat it passes through the minimal virus scanning that the company has in place. Later, a claims manager downloads this file onto their computer and opens it — resulting in an endpoint infected with an Advanced Persistent Threat (APT). From the attacker's perspective, this was actually easier than phishing because they didn't even need to send any emails.

10 Nifty Tips To Bolster Selenium Test Automation

It is now common to see businesses that have transitioned to Selenium test automation. And with reliable feedback on brand-new features, it is easy to see why automated browser testing has become the new norm.

Although there are no rigid guidelines for composing Selenium test automation scripts, there are unwritten rules that you can follow to write much better test scripts.

Sysdig: What It Is and How to Use It

Sysdig is a universal system visibility tool with support for containers. What makes Sysdig special, is that it hooks itself into the machine's kernel and segregates the information on a per-container basis.
For the scope of this tutorial, we will focus on the open-source version of Sysdig.

In the next sections, you will:

Goodbye, ManageWP.org; Hello, WP Content

Yesterday, Iain Poulson and Ashley Rich launched community-curated, news-sharing site WP Content. The launch comes on the heels of ManageWP.org shutting down its own news-sharing service and the WordPress community losing out on a valuable resource.

Both Poulson and Rich are based in the UK and work for Delicious Brains, a development company that focuses on building products for WordPress. Their new venture was met with enthusiasm when Poulson first announced it on Twitter.

The front page of WPContent.io, which displays trending and recent stories.
Homepage of WPContent.io.

Long before I was a writer for WP Tavern and needed to keep an eye out for the latest news, ManageWP.org was one of my go-to sources for catching up with everything happening in the WordPress community. There is always so much going on that even the Tavern cannot stay on top of it all. ManageWP.org helped me become a voracious reader of ideas, tutorials, and other news within the industry. For that, I am certain I owe the team a debt that cannot be repaid.

After shutting the doors, they left us with a message on the site that read, “After many years of serving the WordPress community, we’ve made the difficult decision to shut down ManageWP.org. Several factors led us here, but it ultimately came down to the team being unable to give ManageWP.org the attention it deserves.”

It is only the news-sharing site at ManageWP.org that is shutting down. The ManageWP.com company and service are still alive and well.

ManageWP.org launched when WordPress held a mere 20% of the web back in 2013. GoDaddy acquired the ManageWP company in 2016 but allowed it to operate independently, including the news-sharing site. In many ways, ManageWP.org felt as much a part of the identity of the WordPress community as our site. For seven years, users have shared articles, upvoted their favorites, and found a legitimate source to stay informed on a wide range of topics around WordPress.

“Thank you to everyone who shared inspiring stories, useful resources, and special announcements with us,” read the final message on the site. “It’s been a treat.”

While many of us were disappointed to see the site shut down, sometimes it is time for something new. We can say goodbye to a great service and make room for someone else to take up the mantle. So, goodbye, ManageWP.org. Thanks for all the good years. And, welcome, WP Content.

“After @managewp closed down their community news site, we felt there should be a place where the #WordPress community can submit articles and up vote them,” tweeted the WP Content team.

The newly-built WP Content site is simple to use. It works similarly to other sharing sites such as Reddit. Users can sign up for an account to share stories themselves or upvote other stories. All visitors are free to follow through and read stories without signing up.

The front page of the site shares the currently trending and most recent stories. The site also breaks stories down into the following categories:

  • Business
  • Community
  • Development
  • Plugins
  • Security
  • Tutorials

I welcome the new venture and am glad to see someone filling in what was quickly becoming a missing piece of our community. With luck, WP Content will serve as a great resource for many years to come. The team has some big shoes to fill, but they are off to a great start.

J-Spring Digital 2020 Impressions

This year’s edition of J-Spring, organized by the NLJUG, went digital due to the COVID-19 pandemic. From the 23rd up to and including the 26th of June, every day two technical talks have been held. We attended this digital version of J-Spring and want to share some of our impressions. Enjoy!

1. Introduction

Due to the Corona virus, the NLJUG (the Java User Group in the Netherlands) decided to turn the J-Spring one day physical conference into a digital event. They spread the conference over multiple days in time blocks of 2 up to 2,5 hours. This was a good idea because attending a virtual conference for a whole day can be very exhausting. The event consisted of a fixed program of two talks at the end of each day. A nice ending of every day, we must say! In the following sections, we will share some of our impressions of the several talks.

Kubernetes Admission Controllers

Kubernetes supports over 30 Admission Controllers. Subsequent to Authorization and Authentication, Admission Controllers are the final step in a 3-step process before Kubernetes persists the resource in etcd (a consistent and highly-available key value store used as Kubernetes’ backing store for all cluster data). Some relevant Admission Controllers to secure running containers are:

  • PodSecurityPolicy: this option implements pod admission based on security context and available policies.
  • DenyEscalatingExec: when hackers open shells in privileged containers, they have access to the host. This option ensures that exec and attach commands from privileged containers are blocked.
  • AlwaysPullImages: while there is a performance advantage to storing and reusing image on a node, hygiene and the assurance that you always run up-to-date container images may be important. Since vulnerabilities are patched upstream, pulling images ensures that the latest remediation are always downloaded.
  • LimitRange and ResourceQuota: to prevent denial of service attacks, and any spawning of unauthorized processes from established pods, this option observes incoming requests for violation of these limits.
  • NodeRestriction: this limits the permissions of each kubelet, ensuring that it can only modify pods that are bound to it and its own Node object.

NodeRestriction

This admission controller limits the Node and Pod objects a kubelet can modify. In order to be limited by this admission controller, kubelet must use credentials in the system:node group, with a username in the form system:node:<NodeName>. Such kubelet will only be allowed to modify their own Node API object.

Optimize AWS Solution Architecture for Performance Efficiency

Amazon Web Services (AWS) offers various resources and services to help you build SaaS and PaaS solutions, however, the challenge is to achieve and maintain performance efficiency that has its own important share in delivering business value. This article highlights some of the best practices for designing and operating reliable, secure, efficient, and cost-effective cloud applications that offer performance efficiency. There are two primary areas to focus on:

  1. Select and Configure cloud resources for higher performance
  2. Review and Monitor Performance

Cloud resource