1676380800
A React component for Instagram like stories
npm install --save react-insta-stories
The component responds to actions like tap on right side for next story, on left for previous and tap and hold for pause. Custom time duration for each story can be provided. See it in action here: https://mohitk05.github.io/react-insta-stories/
import React, { Component } from 'react';
import Stories from 'react-insta-stories';
const App = () => {
return (
<Stories
stories={stories}
defaultInterval={1500}
width={432}
height={768}
/>
);
};
Here stories
is an array of story objects, which can be of various types as described below.
Property | Type | Default | Description |
---|---|---|---|
stories | [String/Object] | required | An array of image urls or array of story objects (options described below) |
renderers ⚡️ | [Object] | [] | An array of renderer objects (options described below) |
defaultInterval | Number | 1200 | Milliseconds duration for which a story persists |
loader | Component | Ripple loader | A loader component as a fallback until image loads from url |
header | Component | Default header as in demo | A header component which sits at the top of each story. It receives the header object from the story object. Data for header to be sent with each story object. |
storyContainerStyles | Object | {} | Styles object for the outer container |
width | Number/String | 360 | Width of the component, e.g. 600 or '100vw' or 'inherit' |
height | Number/String | 640 | Height of the component, e.g. 1000 or '100%' or 'inherit' |
storyStyles | Object | none | Override the default story styles mentioned below. |
loop | Boolean | false | The last story loop to the first one and restart the stories. |
New props | ⭐️ | ⭐️ | ⭐️ |
isPaused | Boolean | false | Toggle story playing state |
currentIndex | Number | undefined | Set the current story index |
onStoryStart | Function | - | Callback when a story starts |
onStoryEnd | Function | - | Callback when a story ends |
onAllStoriesEnd | Function | - | Callback when all stories in the array have ended |
keyboardNavigation | Boolean | false | Attaches arrow key listeners to navigate between stories if true. Also adds up arrow key listener for opening See More and Escape/down arrow for closing it |
preventDefault | Boolean | false | Disable the default behavior when user click the component |
Instead of simple string url, a comprehensive 'story object' can also be passed in the stories
array.
Property | Description |
---|---|
url | The url of the resource, be it image or video. |
type | Optional. Type of the story. `type: 'video' |
duration | Optional. Duration for which a story should persist. |
header | Optional. Adds a header on the top. Object with heading , subheading and profileImage properties. |
seeMore | Optional. Adds a see more icon at the bottom of the story. On clicking, opens up this component. (v2: updated to Function instead of element) |
seeMoreCollapsed | Optional. Send custom component to be rendered instead of the default 'See More' text. |
styles | Optional. Override the default story styles mentioned below. |
Following are the default story content styles. Override them by providing your own style object with each story or a global override by using the storyStyles
prop.
storyContent: {
width: 'auto',
maxWidth: '100%',
maxHeight: '100%',
margin: 'auto'
}
To allow reusable components to display story UI, you can pass in pre-built or custom-built components in a special manner to leverage this behavior. Each renderer object has two properties:
renderer
- This is the UI component that will be rendered whenever the object matches certain conditions.tester
- This is a function that tests whether the renderer is suitable for the current story. It receives the current story object to render and returns an object with two properties:condition
- This states if the renderer matches the current story's criteria (a boolean).priority
- A number denoting the priority of the current renderer. E.g. priority of 2 is less than a 5, and if two renderers have condition = true
, their priorities will be compared and the one with higher priority will be selected.So essentially a simple renderer would look like this: (you may also refer the inbuilt Image renderer)
// Renderer.js
export const renderer = ({ story, action, isPaused, config }) => {
return <div>Hello!</div>;
};
export const tester = (story) => {
return {
// Use this renderer only when the story type is video
condition: story.type === 'video',
priority: 3,
};
};
Every renderer
component gets 4 props as shown above. Out of these the story
, action
and isPaused
are as their names suggest. The config
object contains certain global properties which were passed while initialising the component. It looks like this:
const { width, height, loader, storyStyles } = config;
These props can be used to customize the entire UI as required, and then can be packaged as a Node module and shared. If someone else wishes to use your package as a renderer, they can simply pass it inside an array as the
renderers
prop to the main component. If you publish any such renderer, please raise a PR to add it to this list. A few suggestions would be a Markdown renderer, highlighted code renderer, etc.
List of public renderers:
WithSeeMore
This is a wrapper component which includes the UI and logic for displaying a 'See More' link at the bottom of the story. This is available as a named export from the package and can be used to easily add the functionality to a custom content story. It takes in two props - story
and action
.
const { WithSeeMore } from 'react-insta-stories';
const CustomStoryContent = ({ story, action }) => {
return <WithSeeMore story={story} action={action}>
<div>
<h1>Hello!</h1>
<p>This story would have a 'See More' link at the bottom ✨</p>
</div>
</WithSeeMore>
}
You can also send custom 'See More' component for the collapsed state. While using WithSeeMore
, pass in a customCollapsed
prop with a value of your custom component. It will receive a toggleMore
and action
prop to handle clicks on the See More link.
const { WithSeeMore } from 'react-insta-stories';
const customCollapsedComponent = ({ toggleMore, action }) =>
<h2 onClick={() => {
action('pause');
window.open('https://mywebsite.url', '_blank');
}}>
Go to Website
</h2>
const CustomStoryContent = ({ story, action }) => {
return <WithSeeMore
story={story}
action={action}
customCollapsed={customCollapsedComponent}
>
<div>
<h1>Hello!</h1>
<p>This story would have a 'See More' link at the bottom and will open a URL in a new tab.</p>
</div>
</WithSeeMore>
}
If not implementing a custom UI, you can send the customCollapsedComponent
component inside the story object as seeMoreCollapsed
.
const stories = [
{
url: 'some.url',
seeMore: SeeMoreComponent, // when expanded
seeMoreCollapsed: customCollapsedComponent, // when collapsed
},
];
WithHeader
This named export can be used to include the header UI on any custom story. Simply wrap the component with this HOC and pass in some props.
const { WithHeader } from 'react-insta-stories';
const CustomStoryContent = ({ story, config }) => {
return <WithHeader story={story} globalHeader={config.header}>
<div>
<h1>Hello!</h1>
<p>This story would have the configured header!</p>
</div>
</WithHeader>
}
You may also use both these HOCs together, as in the Image renderer.
If you wish to have a bare minimum setup and only need to show image stories, you can simply pass the image urls inside the stories
array. This will show all your images as stories.
import Stories from 'react-insta-stories';
const stories = [
'https://example.com/pic.jpg',
'data:image/jpg;base64,R0lGODl....',
'https://mohitkarekar.com/icon.png',
];
return () => <Stories stories={stories} />;
If plain images does not suffice your usecase, you can pass an object instead of a string. This object supports all the properties mentioned above in the section story object. While using the object type, use url
to denote the source url in case of media.
These properties can be mixed in different ways to obtain desired output.
Duration
Each story can be set to have a different duration.
const stories = [
'https://example.com/pic.jpg',
{
url: 'https://example.com/pic2.jpg',
duration: 5000,
},
];
Header
Adds a header to the story.
const stories = [
'https://example.com/pic.jpg',
{
url: 'https://example.com/pic2.jpg',
duration: 5000,
header: {
heading: 'Mohit Karekar',
subheading: 'Posted 30m ago',
profileImage: 'https://picsum.photos/100/100',
},
},
];
See More
Adds a click to see more option at the bottom of the story. When present, shows the arrow at the bottom and when clicked, shows the provided component.
const stories = [
'https://example.com/pic.jpg',
{
url: 'https://example.com/pic2.jpg',
duration: 5000,
seeMore: SeeMore, // some component
},
{
url: 'https://example.com/pic3.jpg',
duration: 2000,
seeMore: ({ close }) => {
return <div onClick={close}>Hello, click to close this.</div>;
},
},
];
Type
If provided type: video
, then the component loads a video player. All expected features come in automatically. Duration is ignored, if provided and actual video duration is considered.
const stories = [
'https://example.com/pic.jpg',
{
url: 'https://example.com/vid.mp4',
duration: 5000, // ignored
type: 'video',
},
];
Styles
Override default story element styles. Regular style object can be provided.
You can render custom JSX inside a story by sending a content
property inside the story object. If a content
property is present, all other media related properties are ignored. duration
holds true here.
const stories = [
'https://example.com/pic.jpg',
{
content: (props) => (
<div style={{ background: 'pink', padding: 20 }}>
<h1 style={{ marginTop: '100%', marginBottom: 0 }}>🌝</h1>
<h1 style={{ marginTop: 5 }}>A custom title can go here.</h1>
</div>
),
},
];
The content property can hold any React component. For further control, it receives two important props:
action
It allows you to fire play/pause actions.isPaused
Holds true is the story is currently paused, false otherwise.const stories = [
'https://example.com/pic.jpg',
{
content: ({ action, isPaused }) => {
useEffect(() => {
setTimeout(() => {
action('pause');
setTimeout(() => {
action('play');
}, 2000);
}, 2000);
}, []);
return (
<div style={{ background: 'pink', padding: 20 }}>
<h1 style={{ marginTop: '100%', marginBottom: 0 }}>🌝</h1>
<h1>{isPaused ? 'Paused' : 'Playing'}</h1>
</div>
);
},
},
];
In the code above, on render a timeout will be set which would fire a 'pause' action after 2 seconds. Again after 2 seconds, a 'play' action would be fired. In the JSX, isPaused
is used to display the current play state.
To develop this package locally, you can follo these steps:
npm install
.cd example && npm install
cd ..
npm start
npm run example
.This will start a hot-reloading setup with a live example.
react-insta-stories
Do you use react-insta-stories
too? Raise a PR to include your site in this list!
Author: Mohitk05
Source Code: https://github.com/mohitk05/react-insta-stories
License: MIT license
1673744700
Ladle is an environment to develop, test, and share your React components faster.
mkdir my-ladle
cd my-ladle
pnpm init
pnpm add @ladle/react react react-dom
mkdir src
echo "export const World = () => <p>Hey</p>;" > src/hello.stories.tsx
pnpm ladle serve
with yarn
mkdir my-ladle
cd my-ladle
yarn init --yes
yarn add @ladle/react react react-dom
mkdir src
echo "export const World = () => <p>Hey</p>;" > src/hello.stories.tsx
yarn ladle serve
with npm
mkdir my-ladle
cd my-ladle
npm init --yes
npm install @ladle/react react react-dom
mkdir src
echo "export const World = () => <p>Hey</p>;" > src/hello.stories.tsx
npx ladle serve
Author: tajo
Source Code: https://github.com/tajo/ladle
License: MIT license
1633261123
Stories for Flutter
A customizable flutter package that allows you to use Instagram like stories, or WhastApp like statuses in your Flutter app easily, made without using external dependencies.
Step 1: Import the package.
import 'package:stories_for_flutter/stories_for_flutter.dart';
Step 2: Call the stories plugin and use it. Can give Scaffold to each page, making it highly customizable.
Stories(
storyItemList: [
// First group of stories
StoryItem(
name: "First Story", // Name of first story
thumbnail: // Add icon to first story
stories: [
Page1(),
Page2(),
]),
// Second story group
StoryItem(
name: "Second Story",
thumbnail: // Add icon to first story
stories: [
Page1(),
Page2(),
Page3()
],
),
],
);
Example:
Stories(
displayProgress: true,
storyItemList: [
// First group of stories
StoryItem(
name: "First Story",
thumbnail: NetworkImage(
"https://assets.materialup.com/uploads/82eae29e-33b7-4ff7-be10-df432402b2b6/preview",
),
stories: [
// First story
Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://wallpaperaccess.com/full/16568.png",
),
),
),
),
),
// Second story in first group
Scaffold(
body: Center(
child: Text(
"Second story in first group !",
style: TextStyle(
color: Color(0xff777777),
fontSize: 25,
),
),
),
),
]),
// Second story group
StoryItem(
name: "2nd",
thumbnail: NetworkImage(
"https://www.shareicon.net/data/512x512/2017/03/29/881758_cup_512x512.png",
),
stories: [
Scaffold(
body: Center(
child: Text(
"That's it, Folks !",
style: TextStyle(
color: Color(0xff777777),
fontSize: 25,
),
),
),
),
],
),
],
);
Run this command:
With Flutter:
$ flutter pub add stories_for_flutter
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
dependencies: stories_for_flutter: ^1.1.1
Alternatively, your editor might support or flutter pub get
. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:stories_for_flutter/stories_for_flutter.dart';
import 'package:flutter/material.dart';import 'package:stories_for_flutter/stories_for_flutter.dart';void main() { runApp(const MyApp());}class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: const Text('Stories Example'), ), body: Column( children: [ Stories( circlePadding: 2, storyItemList: [ StoryItem( name: "First Story", thumbnail: const NetworkImage( "https://assets.materialup.com/uploads/82eae29e-33b7-4ff7-be10-df432402b2b6/preview", ), stories: [ Scaffold( body: Container( decoration: const BoxDecoration( image: DecorationImage( fit: BoxFit.cover, image: NetworkImage( "https://wallpaperaccess.com/full/16568.png", ), ), ), ), ), Scaffold( body: Container( decoration: const BoxDecoration( image: DecorationImage( fit: BoxFit.cover, image: NetworkImage( "https://i.pinimg.com/originals/2e/c6/b5/2ec6b5e14fe0cba0cb0aa5d2caeeccc6.jpg", ), ), ), ), ), ]), StoryItem( name: "2nd", thumbnail: const NetworkImage( "https://www.shareicon.net/data/512x512/2017/03/29/881758_cup_512x512.png", ), stories: [ Scaffold( body: Container( decoration: const BoxDecoration( image: DecorationImage( fit: BoxFit.cover, image: NetworkImage( "https://i.pinimg.com/originals/31/bc/a9/31bca95ba39157a6cbf53cdf09dda672.png", ), ), ), ), ), const Scaffold( backgroundColor: Colors.black, body: Center( child: Text( "That's it, Folks !", style: TextStyle( color: Color(0xffffffff), fontSize: 25, ), ), ), ), ], ), ], ), ], ), ), ); }}
Download Details:
Author: steevjames
Source Code: https://github.com/steevjames/Stories-for-Flutter
1627285356
Moral Stories In Hindi | Moral Story For Kids | Motivational Story
Here you will get to read a story full of fun entertainment and at the same time you will learn a lot from it.
Best Moral Stories in Hindi for all class that teach us Moral lesson on how to be a better person. Moral Stories in Hindi teaches you how to be a better person in life. Story reading is a unique way for students and adults to develop understanding, respect, and appreciation for other cultures. Best Moral Story in Hindi or Short Motivational Story in Hindi with Moral This article is a collection of the best moral stories that you will find on smarttricsmoralstory blogspot.
And to be Motivated, definitely read our Motivational blog on other smarttricsrk blogspot.
https://smarttricsrk.blogspot.com/?m=1
https://smarttricsmoralstory.blogspot.com/
#moral #stories #kids #entertainment #kahani
1597932120
During this quarantine, we all, in a way or another, have been harassed from a very long lockdown. Although Covid-19 immediately impacted on our economic system, I was still feeling safe in my smart working data scientist role. I was wrong.
My work was to produce machine learning models for a famous cruise brand, that aimed to keep under control environmental impact during fleet navigation. As you can imagine, cruises business had a rough stop during the current pandemic and a lot of related activity with them.
With all the activity stopped, I started to invest my time in studying more, elaborating new technologies and trying to build a bigger network.
My company had a trump card in store for me, though. To continue a full-time job, they proposed to me to develop the backend of a fantasy tennis application with whom we were collaborating.
I wasn’t entirely convinced, because of my lack of software development expertise, in particular using the famous **Django **framework. However, I would never have tried my hand at building an application, but I would have continued on my path as a data scientist. This **unexpected **change allowed me to do something I wasn’t going to do and maybe learn new useful notions that would complete me as a professional working in the world of data and technology in general.
This intuition proved to be correct, and since I will soon be a scientist again, I want to tell you what I have learned from these months of Django development in a few brief considerations.
Don’t worry! It is a few minutes read.
#data-science #software-development #stories #django #data analytic
1595875020
In this step-by-step tutorial, you’ll learn how to launch an AWS Deep Learning AMI. The AMIs are machine images loaded with deep learning frameworks that make it simple to get started with deep learning in minutes.
Using the AMI, you can train custom models, experiment with new algorithms, and learn new deep learning skills and techniques. The AMIs come with pre-installed open source deep learning frameworks including TensorFlow, Apache MXNet, PyTorch, Chainer, Microsoft Cognitive Toolkit, Caffe, Caffe2, Theano, and Keras, optimized for high performance on Amazon EC2 instances. The AMIs also offer GPU and CPU-acceleration through pre-configured drivers, and come with popular Python packages.
#stories #deep learning
1595159178
“Controversial” is literally the most overused word on the Internet, with the possible exception of “literally”. But this time it’s true: some of the charts in our 2018 State of JavaScript survey results generated a lot more debate than others. Let’s see why!
#javascript stories #stories #gender #javascript #tech gap
1592836800
Bombastic opening statement about the strength of the glorious code you’re about to read. Further explanation that clearly you haven’t seen anything as good as this yet.
Unimportant and overlong diatribe explaining why this forthcoming code snippet is critical to the world at large, including meaningless attempt at invoking “think of the children.” Bluntly state that my fellow bloggers have it all wrong, that only I have the true solution. Immediately try to roll back that statement with phrases like “they have their good ideas,” but subtly acknowledge that, yes, I am better than them, thanks for asking.
#stories
1592809140
LISTEN UP RECRUITS! This is Good Code Basic Training! I’m Sergeant Soccly, and it’s my job to get you newbies up to speed on the problems this profession faces so that you can be prepared to deal with them.
Our mission is to fight the evils of bad code design, and the citizens need you meatbags to help us do that. Your nation thanks you for your service, and your contributions will…
Jenkins! Shut your mouth while I’m talking! Or is there something you’d like to share with the rest of us?
#stories #good code
1591239482
Single-SPA Starting From Scratch
single-spa allows you to build micro frontends that coexist and can each be written with their own framework. If you’d like to learn how to use single-spa with Angular, Vue, or other frameworks, checkout this example. And if you’d rather use a different build system instead of webpack, check out this example Read more about separating applications using single-spa.
#article #javascript stories #stories #tech stories #javascript
1588983900
Before we dive in and start building, it’s worth looking at why we might choose Node.js to build a command-line application.
The most obvious advantage is that, if you’re reading this, you’re probably already familiar with it — and, indeed, with JavaScript.
#node.js stories #stories #javascript #nodejs