ion-badge
Badges are inline block elements that usually appear near another element. Typically they contain a number or other characters. They can be used as a notification that there are additional items associated with an element and indicate how many items there are.
Usage
- Angular
- Javascript
- React
- Stencil
- Vue
<!-- Default -->
<ion-badge>99</ion-badge>
<!-- Colors -->
<ion-badge color="primary">11</ion-badge>
<ion-badge color="secondary">22</ion-badge>
<ion-badge color="tertiary">33</ion-badge>
<ion-badge color="success">44</ion-badge>
<ion-badge color="warning">55</ion-badge>
<ion-badge color="danger">66</ion-badge>
<ion-badge color="light">77</ion-badge>
<ion-badge color="medium">88</ion-badge>
<ion-badge color="dark">99</ion-badge>
<!-- Item with badge on left and right -->
<ion-item>
<ion-badge slot="start">11</ion-badge>
<ion-label>My Item</ion-label>
<ion-badge slot="end">22</ion-badge>
</ion-item>
<!-- Default -->
<ion-badge>99</ion-badge>
<!-- Colors -->
<ion-badge color="primary">11</ion-badge>
<ion-badge color="secondary">22</ion-badge>
<ion-badge color="tertiary">33</ion-badge>
<ion-badge color="success">44</ion-badge>
<ion-badge color="warning">55</ion-badge>
<ion-badge color="danger">66</ion-badge>
<ion-badge color="light">77</ion-badge>
<ion-badge color="medium">88</ion-badge>
<ion-badge color="dark">99</ion-badge>
<!-- Item with badge on left and right -->
<ion-item>
<ion-badge slot="start">11</ion-badge>
<ion-label>My Item</ion-label>
<ion-badge slot="end">22</ion-badge>
</ion-item>
import React from 'react';
import { IonBadge, IonItem, IonLabel, IonContent } from '@ionic/react';
export const BadgeExample: React.FC = () => (
<IonContent>
{/*-- Default --*/}
<IonBadge>99</IonBadge>
{/*-- Colors --*/}
<IonBadge color="primary">11</IonBadge>
<IonBadge color="secondary">22</IonBadge>
<IonBadge color="tertiary">33</IonBadge>
<IonBadge color="success">44</IonBadge>
<IonBadge color="warning">55</IonBadge>
<IonBadge color="danger">66</IonBadge>
<IonBadge color="light">77</IonBadge>
<IonBadge color="medium">88</IonBadge>
<IonBadge color="dark">99</IonBadge>
{/*-- Item with badge on left and right --*/}
<IonItem>
<IonBadge slot="start">11</IonBadge>
<IonLabel>My Item</IonLabel>
<IonBadge slot="end">22</IonBadge>
</IonItem>
</IonContent>
);
import { Component, h } from '@stencil/core';
@Component({
tag: 'badge-example',
styleUrl: 'badge-example.css',
})
export class BadgeExample {
render() {
return [
// Default
<ion-badge>99</ion-badge>,
// Colors
<ion-badge color="primary">11</ion-badge>,
<ion-badge color="secondary">22</ion-badge>,
<ion-badge color="tertiary">33</ion-badge>,
<ion-badge color="success">44</ion-badge>,
<ion-badge color="warning">55</ion-badge>,
<ion-badge color="danger">66</ion-badge>,
<ion-badge color="light">77</ion-badge>,
<ion-badge color="medium">88</ion-badge>,
<ion-badge color="dark">99</ion-badge>,
// Item with badge on left and right
<ion-item>
<ion-badge slot="start">11</ion-badge>
<ion-label>My Item</ion-label>
<ion-badge slot="end">22</ion-badge>
</ion-item>,
];
}
}
<template>
<!-- Default -->
<ion-badge>99</ion-badge>
<!-- Colors -->
<ion-badge color="primary">11</ion-badge>
<ion-badge color="secondary">22</ion-badge>
<ion-badge color="tertiary">33</ion-badge>
<ion-badge color="success">44</ion-badge>
<ion-badge color="warning">55</ion-badge>
<ion-badge color="danger">66</ion-badge>
<ion-badge color="light">77</ion-badge>
<ion-badge color="medium">88</ion-badge>
<ion-badge color="dark">99</ion-badge>
<!-- Item with badge on left and right -->
<ion-item>
<ion-badge slot="start">11</ion-badge>
<ion-label>My Item</ion-label>
<ion-badge slot="end">22</ion-badge>
</ion-item>
</template>
<script>
import { IonBadge, IonItem, IonLabel } from '@ionic/vue';
import { defineComponent } from 'vue';
export default defineComponent({
components: { IonBadge, IonItem, IonLabel },
});
</script>
Properties
color
Description | The color to use from your application's color palette. Default options are: "primary" , "secondary" , "tertiary" , "success" , "warning" , "danger" , "light" , "medium" , and "dark" . For more information on colors, see theming. |
Attribute | color |
Type | string | undefined |
Default | undefined |
mode
Description | modeは、どのプラットフォームのスタイルを使用するかを決定します。 |
Attribute | mode |
Type | "ios" | "md" |
Default | undefined |
Events
No events available for this component.
Methods
No public methods available for this component.
CSS Shadow Parts
No CSS shadow parts available for this component.
CSS Custom Properties
Name | Description |
---|---|
--background | バッジの背景 |
--color | バッジの文字色 |
--padding-bottom | バッジのBottom Padding |
--padding-end | バッジの向きが左から右の場合はRight Padding、右から左の場合はLeft Paddingとなります。 |
--padding-start | バッジの向きが左から右の場合はLeft Padding、右から左の場合はRight Paddingとなります。 |
--padding-top | バッジのTop Padding |
Slots
No slots available for this component.