Skip to content

Instantly share code, notes, and snippets.

@SachaG
Last active February 3, 2025 01:58
Show Gist options
  • Save SachaG/be85f94afecd5839fa781ce92a92bf41 to your computer and use it in GitHub Desktop.
Save SachaG/be85f94afecd5839fa781ce92a92bf41 to your computer and use it in GitHub Desktop.
Workshop: The CSS of State of JS

Watch the workshop on YouTube

Who, What Why

Philosophy:

Use the web to make surveys (more) fun

Also:

Handle 5+ surveys by myself without burning out

Workshop

The Stack

  • GraphQL to load data
  • Gatsby to build site
    • considering migration to Astro in the future
  • React
  • TypeScript
  • SCSS
  • Radix
  • D3
    • useful utilities (e.g. for generating scales) even outside of D3 charts
  • [deprecated] Styled-components

The Charts

  • Before: Nivo
  • Now: HTML/CSS/SVG

Why?

  • Full compatibility
    • use same components (tooltips, etc.) inside and outside charts
  • Full interactivity
    • not limited to SVG-compatible elements/interactions
Screenshot 2024-12-05 at 17 21 20
  • Responsiveness
    • SVG, Canvas, etc. are not responsive
  • [in theory] 100% server-rendered with RSCs
    • avoid sending data/text to the client

Line Chart

https://2023.stateofjs.com/en-US/libraries/front-end-frameworks/

Screenshot 2024-12-05 at 15 59 16
  • .chart-columns CSS Grid
    • (--totalColumns + 2) columns, 2 rows
    • grid-template-columns: min-content repeat(var(--totalColumns), 1fr) min-content;
    • grid-template-rows: var(--contentHeight) min-content;
      • we use a fixed chart height
    • nested subgrid
  • SVG element inside .chart-lines-wrapper
  • Future CSS: draw lines from point to point with anchor positioning?

Horizontal Bar Chart

https://2023.stateofjs.com/en-US/demographics/#age

Screenshot 2024-12-05 at 16 03 29
  • .chart-rows CSS Grid
  • three columns: min-content 1fr min-content
  • each bar receives CSS variables:
    • --percentageValue: 32.35; --width: 74.35072397150081; --offset: 0; --color1: #A978FC; --color2: #D1B6FD;

Responsive Chart

  • lose parent-level display: grid;
  • each row is now its own Grid

Stacked Bars

Screenshot 2024-12-05 at 16 16 12
  • uses position: absolute; to dynamically offset bars depending on sort.
Screenshot 2024-12-05 at 16 25 11

SVG "font"

Screenshot 2024-12-05 at 16 11 57
  • how do you add a stroke to text on the web?
    • each label letter is an individual SVG taken from a SVG "font"

Animated Grouping

https://2023.stateofjs.com/en-US/libraries/#all_tools_experience

Screenshot 2024-12-05 at 17 22 44
  • same .chart-rows grid as before
  • position: absolute enables:
    • dynamic offset/alignment
    • group animation
      • no native CSS way to animate DOM order change currently

Q&A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment