Categories
Chakra UI Vue

UI Development with Chakra UI Vue — Breadcrumbs

Chakra UI Vue is a UI framework made for Vue.js that lets us add good-looking UI components into our Vue app.

This article will look at how to get started with UI development with Chakra UI Vue.

Breadcrumbs

Chakra UI Vue comes with a breadcrumb component we can use to add navigation.

To add it, we write:

<template>
  <c-box maxW="sm" border-width="1px" rounded="lg" overflow="hidden">
    <c-breadcrumb :add-separator="false">
      <c-breadcrumb-item>
        <c-breadcrumb-link href="/google">Breadcrumb 1</c-breadcrumb-link>
        <c-breadcrumb-separator
          color="tomato"
          font-size="10px"
          font-weight="bold"
        />
      </c-breadcrumb-item>

<c-breadcrumb-item>
        <c-breadcrumb-link href="/yahoo">Breadcrumb 2</c-breadcrumb-link>
        <c-breadcrumb-separator color="firebrick" font-size="20px" />
      </c-breadcrumb-item>

      <c-breadcrumb-item isCurrentPage>
        <c-breadcrumb-link href="/about">Breadcrumb 2</c-breadcrumb-link>
      </c-breadcrumb-item>
    </c-breadcrumb>
  </c-box>
</template>

<script>
import {
  CBox,
  CBreadcrumb,
  CBreadcrumbItem,
  CBreadcrumbLink,
  CBreadcrumbSeparator,
} from "@chakra-ui/vue";
export default {
  components: {
    CBox,
    CBreadcrumb,
    CBreadcrumbItem,
    CBreadcrumbLink,
    CBreadcrumbSeparator,
  },
};
</script>

We register the CBreadcrumb, CBreadcrumbItem, CBreadcrumbLink, and CBreadcrumbSeparator components to add breadcrumbs into our app.

CBreadcrumb is the main container.

CBreadcrumbItem is the container for a breadcrumb item.

CBreadcrumbLink is a breadcrumb link component.

And CBreadcrumbSeparator is the breadcrumb item separator.

href has the URL to go to when we click on the link.

If we use Vue Router or Nuxt, we can as the as prop to router-link or nuxt-link respectively.

And we set the URL with the to prop instead of href .

Conclusion

We can add breadcrumbs into our Vue app with Chakra UI Vue.

Categories
Chakra UI Vue

UI Development with Chakra UI Vue — Box

Chakra UI Vue is a UI framework made for Vue.js that lets us add good-looking UI components into our Vue app.

This article will look at how to get started with UI development with Chakra UI Vue.

Box

We can use the c-box component to add a flex container into our Vue app.

For instance, we can write:

<template>
  <c-box bg="tomato" w="100%" p="4" color="white"> This is the Box </c-box>
</template>

<script>
import { CBox } from "@chakra-ui/vue";
export default {
  components: {
    CBox,
  },
};
</script>

to add a container with c-box .

bg is the background color.

w is the width.

p is the padding in pixels.

color is the content color.

We can use c-box to house other components.

For instance, we can write:

<template>
  <c-box maxW="sm" border-width="1px" rounded="lg" overflow="hidden">
    <c-image
      src="https://images.unsplash.com/photo-1570129477492-45c003edd2be?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80"
    />
    <c-box d="flex" align-items="baseline">
      <c-badge rounded="full" px="2" variant-color="green"> New </c-badge>
      <c-box
        color="gray.500"
        font-weight="semibold"
        letter-spacing="wide"
        font-size="xs"
        text-transform="uppercase"
        ml="2"
      >
        2 beds &bull; 2 baths
      </c-box>
    </c-box>
  </c-box>
</template>

<script>
import { CBox, CBadge, CImage } from "@chakra-ui/vue";
export default {
  components: {
    CBox,
    CBadge,
    CImage,
  },
};
</script>

to add an image with the c-image component inside.

And we have another c-box inside the outer one.

We make it a flex container with the d prop set to flex .

align-items set the align-items CSS property.

border-width sets the border width.

rounded adds border-radius.

maxW sets the max-width.

Conclusion

We can add a flex container into our Vue app with Chakra UI Vue.

Categories
Chakra UI Vue

UI Development with Chakra UI Vue — Badges

Chakra UI Vue is a UI framework made for Vue.js that lets us add good-looking UI components into our Vue app.

This article will look at how to get started with UI development with Chakra UI Vue.

Badge

We can add badges with Chakra UI Vue.

To do this, we write:

<template>  
  <c-box>  
    <c-badge>Default</c-badge>  
  </c-box>  
</template>  
<script>  
import { CBadge, CBox } from "@chakra-ui/vue";  
export default {  
  components: {  
    CBadge,  
    CBox,  
  },  
};  
</script>

We add the CBadge component to add a badge.

Also, we can use the mx prop to add margins to all sides and the variant-color prop to add a color scheme to the badge:

<template>  
  <c-box>  
    <c-badge mx="2" variant-color="green">Default</c-badge>  
  </c-box>  
</template>  
<script>  
import { CBadge, CBox } from "@chakra-ui/vue";  
export default {  
  components: {  
    CBadge,  
    CBox,  
  },  
};  
</script>

Also, we can put the badge inside a CText component to add the badge beside the text:

<template>  
  <c-box>  
    <c-text font-weight="bold">  
      Jonathan  
      <c-badge :mt="-1" font-size="1em" variant-color="green"> New </c-badge>  
    </c-text>  
  </c-box>  
</template>  
<script>  
import { CBadge, CBox, CText } from "@chakra-ui/vue";  
export default {  
  components: {  
    CBadge,  
    CBox,  
    CText,  
  },  
};  
</script>

The font-size prop sets the font size of the content.

Conclusion

We can add a badge easily with Chakra UI Vue.

Categories
Chakra UI Vue

UI Development with Chakra UI Vue — Avatars

Chakra UI Vue is a UI framework made for Vue.js that lets us add good-looking UI components into our Vue app.

This article will look at how to get started with UI development with Chakra UI Vue.

Avatars

Chakra UI Vue comes with an avatar component.

For instance, we can write:

<template>
  <c-box>
    <c-avatar name="dog" src="https://picsum.photos/id/237/200" />
  </c-box>
</template>
<script>
import { CAvatar, CBox } from "@chakra-ui/vue";
export default {
  components: {
    CAvatar,
    CBox,
  },
};
</script>

to register the CAvatar component to add an avatar image.

The src prop has the URL of the image.

name has the text description of the image.

We can set the size prop to set its size.

The possible values are 2xs, xs, sm, md, lg xl and 2xl , with 2xs being the smallest and 2xl being the largest.

So we can write:

<template>
  <c-box>
    <c-avatar size="lg" name="dog" src="https://picsum.photos/id/237/200" />
  </c-box>
</template>
<script>
import { CAvatar, CBox } from "@chakra-ui/vue";
export default {
  components: {
    CAvatar,
    CBox,
  },
};
</script>

to make the avatar bigger than the default.

We can add a badge to the bottom right corner of the avatar with the CAvatarBagde component:

<template>
  <c-box>
    <c-avatar size="lg" name="dog" src="https://picsum.photos/id/237/200">
      <c-avatar-badge size="1.0em" bg="green.500" />
    </c-avatar>
  </c-box>
</template>
<script>
import { CAvatar, CAvatarBadge, CBox } from "@chakra-ui/vue";
export default {
  components: {
    CAvatar,
    CAvatarBadge,
    CBox,
  },
};
</script>

size sets the size and bg sets the background color.

Conclusion

We can add an avatar easily into our Vue app with Chakra UI Vue.

Categories
Chakra UI Vue

UI Development with Chakra UI Vue — Aspect Ratio Box

Chakra UI Vue is a UI framework made for Vue.js that lets us add good-looking UI components into our Vue app.

This article will look at how to get started with UI development with Chakra UI Vue.

Aspect Ratio Box

We can use the CAspectRatioBox component to add a container that maintains its aspect ratio when we resize it.

For instance, we can write:

<template>
  <c-box>
    <c-aspect-ratio-box max-w="560px" :ratio="1">
      <c-box
        as="iframe"
        title="naruto"
        src="https://www.youtube.com/embed/QhBnZ6NPOY0"
        allow-full-screen
      />
    </c-aspect-ratio-box>
  </c-box>
</template>

<script>
import { CAspectRatioBox, CBox } from "@chakra-ui/vue";

export default {
  components: {
    CAspectRatioBox,
    CBox,
  },
};
</script>

We register the CAspectRatioBox component to add it.

Then we set the ratio prop to the aspect ratio we want.

max-w is the max-width of the container.

We add a c-box with the as prop set to iframe and src set to a YouTube video URL to embed a video.

To add an image, we can write:

<template>
  <c-box>
    <c-aspect-ratio-box max-w="560px" :ratio="1">
      <c-image src="https://picsum.photos/200" alt="image" object-fit="cover" />
    </c-aspect-ratio-box>
  </c-box>
</template>

<script>
import { CAspectRatioBox, CBox, CImage } from "@chakra-ui/vue";

export default {
  components: {
    CAspectRatioBox,
    CBox,
    CImage,
  },
};
</script>

We just put a c-image component inside the c-aspect-ratio-box to make the image maintain its aspect ratio.

Conclusion

We can add the c-aspect-ratio-box component to add a container than maintains the aspect ratio of the contents inside with Chakra UI Vue.