Giter Site home page Giter Site logo

Comments (3)

deadcoder0904 avatar deadcoder0904 commented on May 20, 2024

I got a little closer but I want days, hours next to the numbers where , is https://codesandbox.io/s/flip-padding-not-working-bqmwg?file=/src/EventCountdown.js

flip

from flip.

deadcoder0904 avatar deadcoder0904 commented on May 20, 2024

Got close. No idea how to split the values? Probably need a new transform to split array values.

flip

import React, { useRef, useEffect, useState } from "react";
import Tick from "@pqina/flip";

export const EventCountdown = ({ value }) => {
  const divRef = useRef();
  const tickRef = useRef();

  const [tickValue, setTickValue] = useState(value);

  // Make the Tick instance and store it in the refs
  useEffect(() => {
    const didInit = tick => {
      tickRef.current = tick;
    };

    const currDiv = divRef.current;
    const tickValue = tickRef.current;
    Tick.DOM.create(currDiv, {
      value,
      didInit
    });
    return () => Tick.DOM.destroy(tickValue);
  }, [value]);

  // Start the Tick.down process
  useEffect(() => {
    const counter = Tick.count.down(value, {
      format: ["d", "h", "m", "s"]
    });

    // When the counter updates, update React's state value
    counter.onupdate = function(value) {
      setTickValue(value);
    };

    return () => {
      counter.timer.stop();
    };
  }, [value]);

  // When the tickValue is updated, update the Tick.DOM element
  useEffect(() => {
    if (tickRef.current) {
      tickRef.current.value = tickValue;
    }
  }, [tickValue]);

  return (
    <div className="tick">
      <div data-repeat="true" data-layout="horizontal fit">
        <div className="tick-group">
          <div ref={divRef}>
            <span data-view="flip" />
            <span className="tick-text-inline">Days</span>
            <span data-view="flip" />
            <span className="tick-text-inline">Hours</span>
            <span data-view="flip" />
            <span className="tick-text-inline">Minutes</span>
            <span data-view="flip" />
            <span className="tick-text-inline">Seconds</span>
          </div>
        </div>
      </div>
    </div>
  );
};

from flip.

deadcoder0904 avatar deadcoder0904 commented on May 20, 2024

Ahh jeez got it working. Always happens after I post an issue 🤦

flip

import React, { useRef, useEffect, useState } from "react";
import Tick from "@pqina/flip";

export const EventCountdown = ({ value }) => {
  const divRef = useRef();
  const tickRef = useRef();

  const [tickValue, setTickValue] = useState(value);

  // Make the Tick instance and store it in the refs
  useEffect(() => {
    const didInit = tick => {
      tickRef.current = tick;
    };

    const currDiv = divRef.current;
    const tickValue = tickRef.current;
    Tick.DOM.create(currDiv, {
      value,
      didInit
    });
    return () => Tick.DOM.destroy(tickValue);
  }, [value]);

  // Start the Tick.down process
  useEffect(() => {
    const counter = Tick.count.down(value, {
      format: ["d", "h", "m", "s"]
    });

    // When the counter updates, update React's state value
    counter.onupdate = function(value) {
      setTickValue(value);
    };

    return () => {
      counter.timer.stop();
    };
  }, [value]);

  // When the tickValue is updated, update the Tick.DOM element
  useEffect(() => {
    if (tickRef.current) {
      tickRef.current.value = {
        days: tickValue[0],
        hours: tickValue[1],
        minutes: tickValue[2],
        seconds: tickValue[3]
      };
    }
  }, [tickValue]);

  return (
    <div className="tick">
      <div data-repeat="true" data-layout="horizontal fit">
        <div className="tick-group">
          <div ref={divRef}>
            <span data-key="days" data-transform="pad(00)" data-view="flip" />
            <span className="tick-text-inline">Days</span>
            <span data-key="hours" data-transform="pad(00)" data-view="flip" />
            <span className="tick-text-inline">Hours</span>
            <span
              data-key="minutes"
              data-transform="pad(00)"
              data-view="flip"
            />
            <span className="tick-text-inline">Minutes</span>
            <span
              data-key="seconds"
              data-transform="pad(00)"
              data-view="flip"
            />
            <span className="tick-text-inline">Seconds</span>
          </div>
        </div>
      </div>
    </div>
  );
};

from flip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.