본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

ion-text

원문 보기 위키 갱신

어떤 요소의 텍스트 색상을 스타일링하는 데 쓰는 간단한 컴포넌트인 ion-text예요. 요소의 텍스트 색상을 바꾸려면 그 요소를 ion-text로 감싸면 돼요.

출처: 문서

본문

Encapsulation: shadow

Text 컴포넌트는 어떤 요소의 텍스트 색상을 스타일링하는 데 쓸 수 있는 간단한 컴포넌트예요. 해당 요소의 텍스트 색상을 바꾸려면 ion-text 요소가 그 요소를 감싸야 해요.

Basic Usage

JavaScript

index.html

<ion-text color="primary">
  <h1>H1: The quick brown fox jumps over the lazy dog</h1>
</ion-text>

<ion-text color="secondary">
  <h2>H2: The quick brown fox jumps over the lazy dog</h2>
</ion-text>

<ion-text color="tertiary">
  <h3>H3: The quick brown fox jumps over the lazy dog</h3>
</ion-text>

<p>
  <ion-text color="warning"><ion-icon name="warning"></ion-icon></ion-text>
  I saw a werewolf with a Chinese menu in his hand. Walking through the
  <ion-text color="success"><sub>streets</sub></ion-text> of Soho in the rain. He
  <ion-text color="medium"><i>was</i></ion-text> looking for a place called Lee Ho Fook's. Gonna get a
  <ion-text color="danger">big dish of beef chow mein.</ion-text>
</p>

index.ts

import { defineCustomElements } from '@ionic/core/loader';

import { addIcons } from 'ionicons';
import { warning } from 'ionicons/icons';

/* Core CSS required for Ionic components to work properly */
import '@ionic/core/css/core.css';

/* Basic CSS for apps built with Ionic */
import '@ionic/core/css/normalize.css';
import '@ionic/core/css/structure.css';
import '@ionic/core/css/typography.css';

/* Optional CSS utils that can be commented out */
import '@ionic/core/css/padding.css';
import '@ionic/core/css/float-elements.css';
import '@ionic/core/css/text-alignment.css';
import '@ionic/core/css/text-transformation.css';
import '@ionic/core/css/flex-utils.css';
import '@ionic/core/css/display.css';

/**
 * Ionic Dark Palette
 * -----------------------------------------------------
 * For more information, please see:
 * https://ionicframework.com/docs/theming/dark-mode
 */

// import '@ionic/core/css/palettes/dark.always.css';
// import '@ionic/core/css/palettes/dark.class.css';
import '@ionic/core/css/palettes/dark.system.css';

/* Theme variables */
import './theme/variables.css';

/**
 * On Ionicons 7.2+ this icon
 * gets mapped to a "warning" key.
 * Alternatively, developers can do:
 * addIcons({ 'warning': warning });
 */
addIcons({ warning });

defineCustomElements();

Angular

src/app/example.component.html

<ion-text color="primary">
  <h1>H1: The quick brown fox jumps over the lazy dog</h1>
</ion-text>

<ion-text color="secondary">
  <h2>H2: The quick brown fox jumps over the lazy dog</h2>
</ion-text>

<ion-text color="tertiary">
  <h3>H3: The quick brown fox jumps over the lazy dog</h3>
</ion-text>

<p>
  <ion-text color="warning"><ion-icon name="warning"></ion-icon></ion-text>
  I saw a werewolf with a Chinese menu in his hand. Walking through the
  <ion-text color="success"><sub>streets</sub></ion-text> of Soho in the rain. He
  <ion-text color="medium"><i>was</i></ion-text> looking for a place called Lee Ho Fook's. Gonna get a
  <ion-text color="danger">big dish of beef chow mein.</ion-text>
</p>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonIcon, IonText } from '@ionic/angular';

import { addIcons } from 'ionicons';
import { warning } from 'ionicons/icons';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonIcon, IonText],
})
export class ExampleComponent {
  constructor() {
    /**
     * Any icons you want to use in your application
     * can be registered in app.component.ts and then
     * referenced by name anywhere in your application.
     */
    addIcons({ warning });
  }
}

React

import React from 'react';
import { IonText, IonIcon } from '@ionic/react';
import { warning } from 'ionicons/icons';

function Example() {
  return (
    <>
      <IonText color="primary">
        <h1>H1: The quick brown fox jumps over the lazy dog</h1>
      </IonText>

      <IonText color="secondary">
        <h2>H2: The quick brown fox jumps over the lazy dog</h2>
      </IonText>

      <IonText color="tertiary">
        <h3>H3: The quick brown fox jumps over the lazy dog</h3>
      </IonText>

      <p>
        <IonText color="warning">
          <IonIcon icon={warning}></IonIcon>
        </IonText>
        I saw a werewolf with a Chinese menu in his hand. Walking through the{' '}
        <IonText color="success">
          <sub>streets</sub>
        </IonText>{' '}
        of Soho in the rain. He{' '}
        <IonText color="medium">
          <i>was</i>
        </IonText>{' '}
        looking for a place called Lee Ho Fook's. Gonna get a{' '}
        <IonText color="danger">big dish of beef chow mein.</IonText>
      </p>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-text color="primary">
    <h1>H1: The quick brown fox jumps over the lazy dog</h1>
  </ion-text>

  <ion-text color="secondary">
    <h2>H2: The quick brown fox jumps over the lazy dog</h2>
  </ion-text>

  <ion-text color="tertiary">
    <h3>H3: The quick brown fox jumps over the lazy dog</h3>
  </ion-text>

  <p>
    <ion-text color="warning"><ion-icon :icon="warning"></ion-icon></ion-text>
    I saw a werewolf with a Chinese menu in his hand. Walking through the
    <ion-text color="success"><sub>streets</sub></ion-text> of Soho in the rain. He
    <ion-text color="medium"><i>was</i></ion-text> looking for a place called Lee Ho Fook's. Gonna get a
    <ion-text color="danger">big dish of beef chow mein.</ion-text>
  </p>
</template>

<script setup lang="ts">
  import { IonIcon, IonText } from '@ionic/vue';
  import { warning } from 'ionicons/icons';
</script>

Theming

Text 컴포넌트는 Ionic이 제공하는 기본 colors를 변경해서 커스터마이즈할 수 있어요.

Properties

color

Description: 앱의 색상 팔레트에서 사용할 색상이에요. 기본 옵션은 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", "dark"예요. 색상에 대한 자세한 내용은 theming 문서를 참고해 주세요.

Attribute: color

Type: "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined

Default: undefined

mode

Description: mode는 어떤 플랫폼 스타일을 사용할지 결정해요. 이 값은 초기화할 때 한 번 설정되는 virtual property라서, 첫 렌더링 이후에 값을 바꿔도 업데이트되지 않아요.

Attribute: mode

Type: "ios" | "md"

Default: undefined

Events

이 컴포넌트에는 사용할 수 있는 이벤트가 없어요.

Methods

이 컴포넌트에는 공개된 메서드가 없어요.

CSS Shadow Parts

이 컴포넌트에는 사용할 수 있는 CSS shadow part가 없어요.

CSS Custom Properties

이 컴포넌트에는 사용할 수 있는 CSS 커스텀 프로퍼티가 없어요.

Slots

Name Description
기본 슬롯이에요.

더 알아보기 (Learn more)

text 컴포넌트는 color 프로퍼티만으로 텍스트 색상을 쉽게 바꿀 수 있는 가벼운 래퍼예요. 단락이나 제목 등의 요소를 감싸서 원하는 색상을 적용해 보세요. 색상 테마에 대한 더 자세한 내용은 theming 문서에서 확인할 수 있어요.