项目作者: pjb0811

项目描述 :
components using react & react-motion
高级语言: TypeScript
项目地址: git://github.com/pjb0811/react-motion-components.git
创建时间: 2018-09-12T07:16:11Z
项目社区:https://github.com/pjb0811/react-motion-components

开源协议:

下载


react-motion-components

components using react & react-motion

NPM JavaScript Style Guide

Install

  1. npm install --save react-motion-components

Usage

demo

  1. import React, { Component } from 'react';
  2. import { Carousel } from 'react-motion-components';
  3. export default class CarouselSample extends Component {
  4. state = {
  5. index: 0,
  6. size: 5,
  7. effect: '3d',
  8. colors: ['green', 'red', 'blue', 'yellow', 'black']
  9. };
  10. prev = () => {
  11. const { index, size, effect } = this.state;
  12. this.setState({
  13. index: effect === '2d' ? (index > 0 ? index - 1 : size - 1) : index - 1
  14. });
  15. };
  16. next = () => {
  17. const { index, size, effect } = this.state;
  18. this.setState({
  19. index: effect === '2d' ? (index < size - 1 ? index + 1 : 0) : index + 1
  20. });
  21. };
  22. move = index => {
  23. this.setState({
  24. index
  25. });
  26. };
  27. render() {
  28. const defaultStyle = {
  29. width: 300,
  30. height: 300,
  31. margin: '0 auto',
  32. overflow: 'hidden'
  33. };
  34. const itemStyle = {
  35. display: 'flex',
  36. justifyContent: 'center',
  37. alignItems: 'center',
  38. fontSize: 30,
  39. fontWeight: 'bold',
  40. color: 'white'
  41. };
  42. return (
  43. <div>
  44. <h1>Carousel</h1>
  45. <button onClick={this.prev}>prev</button>
  46. <button onClick={this.next}>next</button>
  47. {Array.from({ length: this.state.size }, (x, i) => {
  48. return (
  49. <button
  50. key={i}
  51. onClick={() => {
  52. this.move(i);
  53. }}
  54. >
  55. move {i}
  56. </button>
  57. );
  58. })}
  59. <div
  60. style={{
  61. ...defaultStyle
  62. }}
  63. >
  64. <Carousel
  65. {...defaultStyle}
  66. direction={'horizontal'}
  67. effect={this.state.effect}
  68. index={this.state.index}
  69. onClick={() => {}}
  70. onChange={index => {
  71. this.move(index);
  72. }}
  73. >
  74. {Array.from({ length: this.state.size }, (x, i) => {
  75. return (
  76. <div
  77. key={i}
  78. style={{
  79. ...defaultStyle,
  80. ...itemStyle,
  81. background: this.state.colors[i]
  82. }}
  83. >
  84. {i}
  85. </div>
  86. );
  87. })}
  88. </Carousel>
  89. </div>
  90. </div>
  91. );
  92. }
  93. }

Cube

demo

  1. import React, { Component } from 'react';
  2. import { Cube } from 'react-motion-components';
  3. class App extends Component {
  4. render() {
  5. const defaultStyle = {
  6. width: 300,
  7. height: 300
  8. };
  9. return (
  10. <div>
  11. <h1>Cube</h1>
  12. <div
  13. style={{
  14. ...defaultStyle
  15. }}
  16. >
  17. <Cube size={300} index="front" ></Cube>
  18. </div>
  19. </div>
  20. );
  21. }
  22. }

DraggableList

demo

  1. import React, { Component } from 'react';
  2. import { DraggableList } from 'react-motion-components';
  3. class App extends Component {
  4. render() {
  5. const defaultStyle = {
  6. width: 300,
  7. height: 300
  8. };
  9. const itemStyle = {
  10. display: 'flex',
  11. justifyContent: 'center',
  12. alignItems: 'center',
  13. fontSize: 30,
  14. fontWeight: 'bold',
  15. color: 'white'
  16. };
  17. return (
  18. <div>
  19. <h1>DraggableList</h1>
  20. <DraggableList {...defaultStyle} rowSize={2}>
  21. <div style={{ ...defaultStyle, ...itemStyle, background: 'green' }}>
  22. 1
  23. </div>
  24. <div style={{ ...defaultStyle, ...itemStyle, background: 'blue' }}>
  25. 2
  26. </div>
  27. <div style={{ ...defaultStyle, ...itemStyle, background: 'red' }}>
  28. 3
  29. </div>
  30. <div style={{ ...defaultStyle, ...itemStyle, background: 'yellow' }}>
  31. 4
  32. </div>
  33. </DraggableList>
  34. </div>
  35. );
  36. }
  37. }

StaggeredList

demo

  1. import React, { Component } from 'react';
  2. import { StaggeredList } from 'react-motion-components';
  3. class App extends Component {
  4. render() {
  5. const defaultStyle = {
  6. width: 200,
  7. height: 200
  8. };
  9. return (
  10. <div>
  11. <h1>StaggeredList</h1>
  12. <div
  13. style={{
  14. ...defaultStyle
  15. }}
  16. >
  17. <StaggeredList>
  18. <div style={{ ...defaultStyle, background: 'green' }} ></div>
  19. <div style={{ ...defaultStyle, background: 'red' }} ></div>
  20. <div style={{ ...defaultStyle, background: 'blue' }} ></div>
  21. </StaggeredList>
  22. </div>
  23. </div>
  24. );
  25. }
  26. }

Window

demo

  1. import React, { Component } from 'react';
  2. import { Header, Segment, Icon } from 'semantic-ui-react';
  3. import 'semantic-ui-css/semantic.min.css';
  4. import { Window } from 'react-motion-components';
  5. class App extends Component {
  6. state = {
  7. window1: {
  8. isOpen: true
  9. }
  10. };
  11. render() {
  12. return (
  13. <div
  14. style={{
  15. textAlign: 'center'
  16. }}
  17. >
  18. <div>
  19. <button
  20. onClick={() => {
  21. this.setState({
  22. window1: {
  23. isOpen: true
  24. }
  25. });
  26. }}
  27. >
  28. add window1
  29. </button>
  30. </div>
  31. <div>
  32. <button
  33. onClick={() => {
  34. this.setState({
  35. window1: {
  36. isOpen: false
  37. }
  38. });
  39. }}
  40. >
  41. remove window1
  42. </button>
  43. </div>
  44. <Window
  45. width={300}
  46. height={300}
  47. minWidth={300}
  48. minHeight={300}
  49. position="top"
  50. direction="top"
  51. titlebar={{
  52. use: true,
  53. height: 50,
  54. component: props => {
  55. const {
  56. width,
  57. height,
  58. toggleWindowSize,
  59. handleMouseDown,
  60. removeWindow,
  61. isFulling
  62. } = props;
  63. return (
  64. <Segment
  65. clearing
  66. attached="top"
  67. style={{
  68. width,
  69. height,
  70. boxSizing: 'border-box'
  71. }}
  72. onDoubleClick={toggleWindowSize}
  73. onMouseDown={handleMouseDown}
  74. >
  75. <Header as="h4" floated="left">
  76. Test
  77. </Header>
  78. <Header as="h4" floated="right">
  79. <Icon
  80. link
  81. color={`${isFulling ? 'green' : 'yellow'}`}
  82. name={`toggle ${isFulling ? 'on' : 'off'}`}
  83. onClick={toggleWindowSize}
  84. ></Icon>
  85. <Icon
  86. link
  87. name="close"
  88. color="red"
  89. onClick={removeWindow}
  90. ></Icon>
  91. </Header>
  92. </Segment>
  93. );
  94. }
  95. }}
  96. resize={true}
  97. open={this.state.window1.isOpen}
  98. onClose={() => {
  99. this.setState({
  100. window1: {
  101. isOpen: false
  102. }
  103. });
  104. }}
  105. >
  106. <Segment
  107. attached
  108. style={{
  109. width: '100%',
  110. height: '100%',
  111. boxSizing: 'border-box'
  112. }}
  113. >
  114. test1
  115. </Segment>
  116. </Window>
  117. </div>
  118. );
  119. }
  120. }

License

MIT © pjb0811