Categories
Shards React

React Development with the Shards React Library — Button

Shards React is a useful UI library that lets us add many components easily into our React app.

In this article, we’ll look at how to use it to add components to our React app.

Button

We can add a button with React Shard’s Button component.

For instance, we can write:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button theme="secondary">Secondary</Button>
    </div>
  );
}

We set the theme to set the background color.

We can also set it to success , danger , info , light , and dark .

If we leave it out, we see a blue background color.

We can add an outlined style with the outline prop:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button outline theme="secondary">
        Secondary
      </Button>
    </div>
  );
}

And we can make it pill-shaped with the pill prop:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button pill theme="secondary">
        Secondary
      </Button>
    </div>
  );
}

We can add all the props together.

Also, we can make it square with the squared prop:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button squared theme="secondary">
        Secondary
      </Button>
    </div>
  );
}

And we can change the size with the size prop:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button size="lg" theme="secondary">
        Secondary
      </Button>
    </div>
  );
}

The active state can be added with the active prop:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button active>Secondary</Button>
    </div>
  );
}

The disabled prop lets us make the button look disabled:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button disabled>Secondary</Button>
    </div>
  );
}

The block prop makes the button display as a block-level element:

import React from "react";
import { Button } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Button block>Secondary</Button>
    </div>
  );
}

Conclusion

We can add buttons with various styles into our React app with Shards React.

Categories
Shards React

React Development with the Shards React Library — Button Groups and Containers

Shards React is a useful UI library that lets us add many components easily into our React app.

In this article, we’ll look at how to use it to add components to our React app.

Button Group

We can add button groups into our React app with Shard Reacr’s ButtonGroip component:

import React from "react";
import { Button, ButtonGroup } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <ButtonGroup>
        <Button>Left</Button>
        <Button>Middle</Button>
        <Button>Right</Button>
      </ButtonGroup>
    </div>
  );
}

We can change the group size with the size prop:

import React from "react";
import { Button, ButtonGroup } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <ButtonGroup size="lg">
        <Button>Left</Button>
        <Button>Middle</Button>
        <Button>Right</Button>
      </ButtonGroup>
    </div>
  );
}

We can also set it to sm or leave it out.

And we can make the group vertical with the vertical prop:

import React from "react";
import { Button, ButtonGroup } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <ButtonGroup vertical>
        <Button>Left</Button>
        <Button>Middle</Button>
        <Button>Right</Button>
      </ButtonGroup>
    </div>
  );
}

Button Toolbar

We can add a button toolbar with the ButtonToolbar component:

import React from "react";
import {
  Button,
  ButtonGroup,
  ButtonToolbar,
  FormInput,
  InputGroup
} from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <ButtonToolbar>
        <ButtonGroup size="sm">
          <Button>Create</Button>
          <Button>Edit</Button>
        </ButtonGroup>

        <InputGroup size="sm" className="ml-auto">
          <FormInput placeholder="Search..." />
        </InputGroup>
      </ButtonToolbar>
    </div>
  );
}

We can add ButtonGroup and InputGroup inside a ButtonToolbar .

Card

Cards let us add containers for content into our React app.

To add it, we write:

import React from "react";
import {
  Card,
  CardHeader,
  CardTitle,
  CardImg,
  CardBody,
  CardFooter,
  Button
} from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Card style={{ maxWidth: "300px" }}>
        <CardHeader>Card header</CardHeader>
        <CardImg src="https://place-hold.it/300x200" />
        <CardBody>
          <CardTitle>Lorem Ipsum</CardTitle>
          <p>Lorem ipsum.</p>
          <Button>Read more</Button>
        </CardBody>
        <CardFooter>Card footer</CardFooter>
      </Card>
    </div>
  );
}

We add a card with various parts.

Card is the card container.

CardHeader has the card header.

CardImg has the card image.

CardBody has the card body.

CardTitle has the card title.

CardFooter has the card footer.

Container

We can use the Collapse component to toggle the visibility of our content.

For instance, we can write:

import React from "react";
import { Container, Row, Col } from "shards-react";
import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Container>
        <Row>
          <Col sm="12" lg="6">
            1 / 2
          </Col>
          <Col sm="12" lg="6">
            2 / 2
          </Col>
        </Row>
      </Container>
    </div>
  );
}

to add the Container com0ponent to add a flexbox container.

Row has the rows. And Col has the columns.

We set the sm and lg props to set the column sizes for those breakpoints.

Conclusion

We can add button groups and containers into our React app with Shards React.

Categories
Shards React

React Development with the Shards React Library — Collapse, Dropdowns, and Fade Effects

Shards React is a useful UI library that lets us add many components easily into our React app.

In this article, we’ll look at how to use it to add components to our React app.

Column Order and Offset

We can set the order and offset of the columns.

For instance, we can write:

import React from "react";
import { Container, Row, Col } from "shards-react";
import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Container>
        <Row>
          <Col sm={{ size: 6, order: 2, offset: 2 }}>2</Col>
          <Col sm={{ size: 2, order: 1, offset: 2 }}>1</Col>
        </Row>
      </Container>
    </div>
  );
}

to set the order property to change the order.

And we can change the offset to change the offset size.

Collapse

We can add a collapse component into our React app with Shards React.

For instance, we can write:

import React, { useState } from "react";
import { Button, Collapse } from "shards-react";
import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  const [collapse, setCollapse] = useState(false);

  const toggle = () => {
    setCollapse((c) => !c);
  };
  return (
    <div className="App">
      <Button onClick={toggle}>Toggle</Button>
      <Collapse open={collapse}>
        <div className="p-3 mt-3 border rounded">
          <h5>Lorem ipsum</h5>
          <span>Lorem ipsum</span>
        </div>
      </Collapse>
    </div>
  );
}

We have the collapse state which we pass into the open prop to control whether the Collapse component is displayed or not.

The Bootstrap styles are required for it to work properly.

Dropdown

We can add dropdowns with the Dropdown , DropdownToggle , DropdownMenu and DropdownItem components.

For instance, we can write:

import React, { useState } from "react";
import {
  Dropdown,
  DropdownToggle,
  DropdownMenu,
  DropdownItem
} from "shards-react";
import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  const [open, setOpen] = useState(false);

  const toggle = () => {
    setOpen((c) => !c);
  };
  return (
    <div className="App">
      <Dropdown open={open} toggle={toggle}>
        <DropdownToggle>Dropdown</DropdownToggle>
        <DropdownMenu>
          <DropdownItem>Action</DropdownItem>
          <DropdownItem>Another action</DropdownItem>
          <DropdownItem>Something else here</DropdownItem>
        </DropdownMenu>
      </Dropdown>
    </div>
  );
}

We add the Dropdown component to add the dropdown container.

DropdownToggle has the dropdown rtoggle.

DropdownMenu has the dropdown menu.

DropdownItem has the dropdown items.

We set the open prop to control when it’s open.

The toggle prop has the toggle function to control the open state.

Fade

The Fade component lets us add a fade effect to our React app.

For instance, we write:

import React, { useState } from "react";
import { Fade, Button } from "shards-react";

import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  const [visible, setVisible] = useState(false);

  const toggle = () => {
    setVisible((c) => !c);
  };
  return (
    <div className="App">
      <Button onClick={toggle} className="mb-2">
        Toggle
      </Button>
      <Fade in={visible} className="p-1">
        lorem ipsum
      </Fade>
    </div>
  );
}

to add a Button to toggle the Fade component.

The in prop lets us set the visibility of the Fade component.

And the toggle function toggles the visible state to control Fade ‘s visibility.

Conclusion

We can add collapse, dropdowns, and fade effects into our React app with Shard React.

Categories
Shards React

Getting Started with React Development with the Shards React Library — Alert, Badge, and Breadcrumbs

Shards React is a useful UI library that lets us add many components easily into our React app.

In this article, we’ll look at how to use it to add components to our React app.

Installation

We can install the package by running:

yarn add shards-react

with Yarn or:

npm i shards-react

with NPM.

Bootstrap styles are required for some components.

We can add it by running:

npm i bootstrap

Alert

After we install the package, we can add an alert with the Alert component:

import React from "react";
import { Alert } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Alert theme="primary">Alert</Alert>
    </div>
  );
}

We import the CSS to import the styles.

We set the theme prop to set background color of the alert.

Other options include secondary , success , danger , info , light , and dark .

We can add a dismissible alert with the dismissible prop:

import React, { useState } from "react";
import { Alert } from "shards-react";
import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";
export default function App() {
  const [visible, setVisible] = useState();
  const dismiss = () => {
    setVisible(false);
  };
  return (
    <div className="App">
      <Alert theme="primary" dismissible={dismiss} open={visible}>
        Alert
      </Alert>
    </div>
  );
}

We set the open prop to the visible state to let us control its visibility.

Badge

We can add a badge into our React app with the Badge component.

For instance, we can write:

import React from "react";
import { Badge } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Badge theme="secondary">Secondary</Badge>
    </div>
  );
}

The theme is set to secondary to display a gray background.

We can also set it to success , danger , info , light , and dark .

If we leave theme out, then it’s set to a blue background.

We can add the pill prop to make it pill-shaped:

import React from "react";
import { Badge } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Badge pill theme="secondary">
        Secondary
      </Badge>
    </div>
  );
}

And we can add the outline prop to make it outlined:

import React from "react";
import { Badge } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Badge outline theme="secondary">
        Secondary
      </Badge>
    </div>
  );
}

We can have both together.

And we can make it a link with the href prop:

import React from "react";
import { Badge } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Badge href="http://yahoo.com" theme="secondary">
        Secondary
      </Badge>
    </div>
  );
}

Breadcrumb

We can add a breadcrumb into our React app with the Breadcrumb and BreadcrumbItem components.

For instance, we can write:

import React from "react";
import { Breadcrumb, BreadcrumbItem } from "shards-react";
import "shards-ui/dist/css/shards.min.css";

export default function App() {
  return (
    <div className="App">
      <Breadcrumb>
        <BreadcrumbItem>
          <a href="#">Home</a>
        </BreadcrumbItem>
        <BreadcrumbItem active>Library</BreadcrumbItem>
      </Breadcrumb>
    </div>
  );
}

BreadcrumbItem has the items. href has the URL for the link.

Conclusion

We can add a few basic components into our React app with Shards React.

Categories
Vue 3

Add a Swiper Carousel into a Vue 3 App with Swiper 6

Swiper for Vue.js lets us add a carousel to our Vue 3 app.

In this article, we’ll look at how to add a carousel into our Vue 3 app with Swiper.

Thumbnail Swiper

We can add a thumbnail swiper into our Vue 3 app with Swiper 6.

For instance, we can write:

<template>
  <swiper :thumbs="{ swiper: thumbsSwiper }">
    <swiper-slide v-for="n of 50" :key="n"
      >Slide {{ n }}</swiper-slide
    >
  </swiper>

  <swiper
    @swiper="setThumbsSwiper"
    watch-slides-visibility
    watch-slides-progress
  >
    <swiper-slide v-for="n of 50" :virtualIndex="n" :key="n"
      >Thumbnail {{ n }}</swiper-slide
    >
  </swiper>
</template>

<script>
import SwiperCore, { Thumbs } from "swiper";
import { Swiper, SwiperSlide } from "swiper/vue";
import "swiper/swiper-bundle.css";

SwiperCore.use([Thumbs]);

export default {
  components: {
    Swiper,
    SwiperSlide,
  },
  data() {
    return {
      thumbsSwiper: null,
    };
  },
  methods: {
    setThumbsSwiper(swiper) {
      this.thumbsSwiper = swiper;
    },
  },
};
</script>

to make the 2nd swiper the thumbnail swiper.

We add the watch-slides-visibility and watch-slides-progress prop to watch the progress of the first slider.

The first swiper is watched because the setThumbsSwiper method is called.

And we set the this.thumbSwiper reactive property to the 2nd swiper.

Effects

Swiper 6 comes with the following effects:

  • Fade
  • Cube
  • Overflow
  • Flip

We can write:

<template>
  <swiper effect="fade">
    <swiper-slide v-for="i of images" :key="i">
      <img :src="i" />
    </swiper-slide>
  </swiper>
</template>

<script>
import SwiperCore, { EffectFade } from "swiper";
import { Swiper, SwiperSlide } from "swiper/vue";
import "swiper/swiper.scss";
import "swiper/components/effect-fade/effect-fade.scss";

SwiperCore.use([EffectFade]);

export default {
  components: {
    Swiper,
    SwiperSlide,
  },
  data() {
    return {
      images: [
        "https://i.picsum.photos/id/23/200/300.jpg?hmac=NFze_vylqSEkX21kuRKSe8pp6Em-4ETfOE-oyLVCvJo",
        "https://i.picsum.photos/id/25/200/300.jpg?hmac=ScdLbPfGd_kI3MUHvJUb12Fsg1meDQEaHY_mM613BVM",
        "https://i.picsum.photos/id/26/200/300.jpg?hmac=E9i_aIqa_ifLvxqI2b1QTLCnhGQYJ83IpvaDfFM54bU",
      ],
    };
  },
};
</script>

to add the effect prop to the swiper component.

We also have to add the SCSS files for the effect animation and SwiperCore.use([EffectFade]) to add the fade effect.

We can add the other effects in similar ways, except we replace the SCSS and the module we call use with.

Conclusion

We can add thumbnail swipers and swiper effects into our Vue 3 app with Swiper 6.