@9gustin/storify-react 中文文档教程

发布于 3年前 浏览 28 项目主页 更新于 3年前

storify :D

React 应用的故事

NPM

v1:

NPM package that show stories in a line (ordered by relevance and date)

URL

How to use

包添加到你的应用程序中

npm i @9gustin/storify-react

Short

App.js

import React from 'react';
import {Storify, useStorify} from '@9gustin/storify-react';
import '@9gustin/storify-react/dist/index.css'
import initialState from './data/stories.json';

function App() {
  const { stories } = useStorify(initialState.stories);

  return (
    <Storify imgSize="5rem" storyBorderColor="blue" stories={stories} viewProfileCallback={(user) => {console.log(user)}}/>
  );
}

export default App;

Detailed

https://www.npmjs.com/package/@9gustin/storify-react component and custom hook

import {Storify, useStorify} from '@9gustin/storify-react';

useStorify (Custom Hook)

ParamTypeDescription
initialStoriesStory[]represent the list of stories to start the state variable
ReturnTypeDescription
storiesStory[]represent the list of stories that are managed in the state, and you should pass it to the Storify component
addStoriesFunction:voidthat function gives you the possibility to add stories, and that's rendered in the Storify component
setStoriesFunction:voidthat function give you the possibility to set the list of stories, and that's rendered in the Storify component

Use:

    const { stories, addStories, setStories } = useStorify(initialStories);

Storify (Component)

Prop NameTypeDescription
imgSizestringrepresent the size of story buttons, receive the css property "width"/"height"
storiesStory[]represent the list of stories that the component should render
viewProfileCallbackFunction:Userthe function that would be called when the user wants to view an user profile
storyBorderColorstringrepresent the color of story buttons borders, that receive the css property border-color

Use:

    <Storify imgSize="5rem" storyBorderColor="blue" stories={stories} viewProfileCallback={(user) => {console.log(user)}}/>

Models

Story

PropertyTypeDescription
userUserthe owner of story
idstringthe identificator of story
createdAtstringthe creation date of story
imageUrlnumberthe url of story image

User

PropertyTypeDescription
usernamestringthe identificator of a user
imageUrlstringthe url of user profile image
relevancenumberthe stories are ordered firstly for the user relevance

About the order of stories

故事(在故事的时间轴中按用户的相关性排序,在故事的createdAt属性之后,首先显示有新故事的用户)。 当用户点击查看来自用户的故事时,会按日期升序(从旧到新)显示

Import styles

import '@9gustin/storify-react/dist/index.css'

Future releases:

  • Next story automatically, with time/progress bar
  • Save actual user in state
  • take response to stories, with a custom callback
  • Button "Add story" with a custom callback
  • Custom stories(colors, to group of persons)

License

MIT © 9gustin

storify :D

stories for you react app

NPMJavaScript Style Guide

v1:

NPM package that show stories in a line(ordered by relevance and date)

URL

https://www.npmjs.com/package/@9gustin/storify-react

How to use

Add package to your aplication

npm i @9gustin/storify-react

Short

App.js

import React from 'react';
import {Storify, useStorify} from '@9gustin/storify-react';
import '@9gustin/storify-react/dist/index.css'
import initialState from './data/stories.json';

function App() {
  const { stories } = useStorify(initialState.stories);

  return (
    <Storify imgSize="5rem" storyBorderColor="blue" stories={stories} viewProfileCallback={(user) => {console.log(user)}}/>
  );
}

export default App;

Detailed

Import the Storify component and custom hook

import {Storify, useStorify} from '@9gustin/storify-react';

useStorify (Custom Hook)

ParamTypeDescription
initialStoriesStory[]represent the list of stories to start the state variable
ReturnTypeDescription
storiesStory[]represent the list of stories that are managed in the state, and you should pass it to the Storify component
addStoriesFunction:voidthat function gives you the possibility to add stories, and that's rendered in the Storify component
setStoriesFunction:voidthat function give you the possibility to set the list of stories, and that's rendered in the Storify component

Use:

    const { stories, addStories, setStories } = useStorify(initialStories);

Storify (Component)

Prop NameTypeDescription
imgSizestringrepresent the size of story buttons, receive the css property "width"/"height"
storiesStory[]represent the list of stories that the component should render
viewProfileCallbackFunction:Userthe function that would be called when the user wants to view an user profile
storyBorderColorstringrepresent the color of story buttons borders, that receive the css property border-color

Use:

    <Storify imgSize="5rem" storyBorderColor="blue" stories={stories} viewProfileCallback={(user) => {console.log(user)}}/>

Models

Story

PropertyTypeDescription
userUserthe owner of story
idstringthe identificator of story
createdAtstringthe creation date of story
imageUrlnumberthe url of story image

User

PropertyTypeDescription
usernamestringthe identificator of a user
imageUrlstringthe url of user profile image
relevancenumberthe stories are ordered firstly for the user relevance

About the order of stories

The stories (in the timeline of stories are ordered by user's relevance, and after by createdAt property of story, the users with new stories are shown first). And when the user clicks to view stories from a user the that's are shown by date ascending(from older to newer)

Import styles

import '@9gustin/storify-react/dist/index.css'

Future releases:

  • Next story automatically, with time/progress bar
  • Save actual user in state
  • take response to stories, with a custom callback
  • Button "Add story" with a custom callback
  • Custom stories(colors, to group of persons)

License

MIT © 9gustin

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文