Comments (3)
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
from flip.
Got close. No idea how to split the values? Probably need a new transform to split array values.
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.
Ahh jeez got it working. Always happens after I post an issue 🤦
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)
- flip demo add data-style="flip-duration:500ms" not working HOT 2
- returning the timestamp and then working fine
- t.shift is not a function HOT 1
- Counter occasionally displays incorrect value... HOT 17
- @pqina/flip for Nuxtjs not working HOT 1
- Layout of "horizontal fill" does not seem to work with the API
- Singular with zero
- Import error in next js HOT 1
- remove last comma ,00 in counter number and the way to custom comma HOT 2
- Flip clock with hours flipper with no leading 0 and centered HOT 1
- Upper and lower half of numbers not aligned
- Shein documentary... HOT 1
- How does data-did-init work with vue? HOT 1
- How to set flip panel mode? HOT 3
- Flip card differs in height HOT 3
- Animation problem in mobile HOT 4
- Feature: is there a way to play sound on animation HOT 3
- If you load the website in a separate tab, the animation does not run HOT 4
- Getting a 1 pixel shift occasionally during flipping HOT 2
- how to set new value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flip.