From 8d99621f3bfd00b5022d86ffb17116b06cf1d0ea Mon Sep 17 00:00:00 2001 From: Andrew Rubin <30575213+andrewrubin@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:40:54 -0800 Subject: [PATCH] Use CSS modules (#15) * fix(docs): add GalleryPaginationItem to table of contents [skip-ci] * refactor: use CSS modules * 4.0.0 * fix: react dependency version * fix: root render * fix: react dependency order * fix: root dep --------- Co-authored-by: Marlon Marcello --- index.html | 8 ++----- package-lock.json | 4 ++-- package.json | 2 +- src/lib/components/gallery-context.jsx | 13 ++++++----- src/lib/components/gallery-item.jsx | 22 +++++++++---------- src/lib/components/gallery-main.jsx | 8 +++---- src/lib/components/gallery-nav.jsx | 10 ++++----- .../components/gallery-pagination-item.jsx | 17 +++++++------- src/lib/components/gallery-pagination.jsx | 8 +++---- .../{gallery.css => gallery.module.css} | 5 ++--- vite.config.js | 5 +++++ 11 files changed, 47 insertions(+), 55 deletions(-) rename src/lib/components/{gallery.css => gallery.module.css} (94%) diff --git a/index.html b/index.html index aad61cd..fe122a6 100644 --- a/index.html +++ b/index.html @@ -7,15 +7,11 @@ @wethegit/react-gallery diff --git a/package-lock.json b/package-lock.json index 19390c3..087de5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@wethegit/react-gallery", - "version": "3.0.4", + "version": "4.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@wethegit/react-gallery", - "version": "3.0.4", + "version": "4.0.0", "license": "MIT", "dependencies": { "prop-types": "~15.8.1" diff --git a/package.json b/package.json index 4e562da..40ecf99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wethegit/react-gallery", - "version": "3.0.4", + "version": "4.0.0", "description": "A customizable, accessible gallery component for React projects.", "files": [ "dist" diff --git a/src/lib/components/gallery-context.jsx b/src/lib/components/gallery-context.jsx index d446bfb..7dc00c6 100644 --- a/src/lib/components/gallery-context.jsx +++ b/src/lib/components/gallery-context.jsx @@ -1,12 +1,9 @@ -// packages import PropTypes from "prop-types" import { createContext, useCallback, useRef, useState, useEffect } from "react" -// utils import classnames from "../utils/classnames" -// styles -import "./gallery.css" +import styles from "./gallery.module.css" export const GalleryContext = createContext() @@ -118,13 +115,17 @@ export const Gallery = ({ return (
{children} {ariaLiveText && ( -

+

{ariaLiveText.replace("$i", activeIndex + 1).replace("$t", items.length)}

)} diff --git a/src/lib/components/gallery-item.jsx b/src/lib/components/gallery-item.jsx index c71e503..7237712 100644 --- a/src/lib/components/gallery-item.jsx +++ b/src/lib/components/gallery-item.jsx @@ -1,12 +1,10 @@ -// packages import PropTypes from "prop-types" -// hooks import { useGallery } from "../hooks/use-gallery" - -// utils import classnames from "../utils/classnames" +import styles from "./gallery.module.css" + export const GalleryItem = ({ index, active, className, children, ...props }) => { const { itemNodes, @@ -28,15 +26,15 @@ export const GalleryItem = ({ index, active, className, children, ...props }) => {...a11yProps} {...props} className={classnames([ - "gallery__item", - draggable && "gallery__item--draggable", - draggable && touchState.offsetting && "gallery__item--dragging", - active && "gallery__item--active", - index === previouslyActiveIndex && "gallery__item--was-active", - index < activeIndex && "gallery__item--left", - index > activeIndex && "gallery__item--right", + styles.gallery__item, + draggable && styles["gallery__item--draggable"], + draggable && touchState.offsetting && styles["gallery__item--dragging"], + active && styles["gallery__item--active"], + index === previouslyActiveIndex && styles["gallery__item--was-active"], + index < activeIndex && styles["gallery__item--left"], + index > activeIndex && styles["gallery__item--right"], (visibleRange === -1 || Math.abs(index - activeIndex) <= visibleRange) && - "gallery__item--visible", + styles["gallery__item--visible"], className, ])} style={{ diff --git a/src/lib/components/gallery-main.jsx b/src/lib/components/gallery-main.jsx index 123bd49..52be78f 100644 --- a/src/lib/components/gallery-main.jsx +++ b/src/lib/components/gallery-main.jsx @@ -1,13 +1,11 @@ -// packages import PropTypes from "prop-types" import { useCallback } from "react" -// hooks import { useGallery } from "../hooks/use-gallery" - -// utils import classnames from "../utils/classnames" +import styles from "./gallery.module.css" + export const GalleryMain = ({ renderGalleryItem, className, ...props }) => { const { activeIndex, @@ -122,7 +120,7 @@ export const GalleryMain = ({ renderGalleryItem, className, ...props }) => { return (
    { const { goToIndex, itemNodes } = useGallery() - const handleClick = (i) => (event) => { + const handleClick = (i) => { goToIndex(i) itemNodes.current[i].focus({ preventScroll: true }) - onClick?.({ event, index }) } return ( -
  • +