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

ion-ripple-effect

원문 보기 위키 갱신

Material Design 잉크 리플 상호작용 효과를 더해 주는 컴포넌트예요. <ion-app> 안에서만 사용할 수 있으며, 어떤 요소 안에든 추가할 수 있습니다.

출처: 문서

본문

Encapsulation: shadow

리플 효과 컴포넌트는 Material Design 잉크 리플 상호작용 효과를 더해 줍니다. 이 컴포넌트는 <ion-app> 안에서만 사용할 수 있고, 어떤 요소 안에든 추가할 수 있어요.

부모 요소에 상대 위치(relative positioning)를 설정하는 것이 중요해요. 리플 효과는 절대 위치(absolute)로 배치되며, 상대 위치가 설정된 가장 가까운 부모를 덮게 되기 때문입니다. 부모 요소에는 ion-activatable 클래스도 주어야 해요. 이 클래스는 리플 효과에게 그 요소가 클릭 가능하다는 것을 알려줍니다. 리플이 컨테이너를 넘칠 경우 부모 요소에 overflow: hidden을 추가하는 것도 권장합니다.

Basic Usage

JavaScript

<div class="wrapper">
  <b>Click on a shape to see the ripple</b>

  <div class="ion-activatable ripple-parent rectangle">
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent rounded-rectangle">
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent circle">
    <ion-ripple-effect></ion-ripple-effect>
  </div>
</div>

<style>
  .wrapper {
    display: flex;
    flex-wrap: wrap;

    align-items: center;
    justify-content: space-between;
    text-align: center;

    height: 300px;
    width: 300px;

    margin: 0 auto;
  }

  b {
    width: 100%;
  }

  .ripple-parent {
    position: relative;
    overflow: hidden;

    border: 1px solid #ddd;
  }

  .rectangle {
    width: 300px;
    height: 150px;
  }

  .rounded-rectangle {
    width: 185px;
    height: 65px;
    border-radius: 8px;
  }

  .circle {
    width: 90px;
    height: 90px;
    border-radius: 50%;
  }
</style>

Angular

src/app/example.component.html

<div class="wrapper">
  <b>Click on a shape to see the ripple</b>

  <div class="ion-activatable ripple-parent rectangle">
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent rounded-rectangle">
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent circle">
    <ion-ripple-effect></ion-ripple-effect>
  </div>
</div>

src/app/example.component.css

.wrapper {
  display: flex;
  flex-wrap: wrap;

  align-items: center;
  justify-content: space-between;
  text-align: center;

  height: 300px;
  width: 300px;

  margin: 0 auto;
}

b {
  width: 100%;
}

.ripple-parent {
  position: relative;
  overflow: hidden;

  border: 1px solid #ddd;
}

.rectangle {
  width: 300px;
  height: 150px;
}

.rounded-rectangle {
  width: 185px;
  height: 65px;
  border-radius: 8px;
}

.circle {
  width: 90px;
  height: 90px;
  border-radius: 50%;
}

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonRippleEffect } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonRippleEffect],
})
export class ExampleComponent {}

React

src/main.tsx

import React from 'react';
import { IonRippleEffect } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <div className="wrapper">
      <b>Click on a shape to see the ripple</b>

      <div className="ion-activatable ripple-parent rectangle">
        <IonRippleEffect></IonRippleEffect>
      </div>

      <div className="ion-activatable ripple-parent rounded-rectangle">
        <IonRippleEffect></IonRippleEffect>
      </div>

      <div className="ion-activatable ripple-parent circle">
        <IonRippleEffect></IonRippleEffect>
      </div>
    </div>
  );
}
export default Example;

src/main.css

.wrapper {
  display: flex;
  flex-wrap: wrap;

  align-items: center;
  justify-content: space-between;
  text-align: center;

  height: 300px;
  width: 300px;

  margin: 0 auto;
}

b {
  width: 100%;
}

.ripple-parent {
  position: relative;
  overflow: hidden;

  border: 1px solid #ddd;
}

.rectangle {
  width: 300px;
  height: 150px;
}

.rounded-rectangle {
  width: 185px;
  height: 65px;
  border-radius: 8px;
}

.circle {
  width: 90px;
  height: 90px;
  border-radius: 50%;
}

Vue

<template>
  <div class="wrapper">
    <b>Click on a shape to see the ripple</b>

    <div class="ion-activatable ripple-parent rectangle">
      <ion-ripple-effect></ion-ripple-effect>
    </div>

    <div class="ion-activatable ripple-parent rounded-rectangle">
      <ion-ripple-effect></ion-ripple-effect>
    </div>

    <div class="ion-activatable ripple-parent circle">
      <ion-ripple-effect></ion-ripple-effect>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { IonRippleEffect } from '@ionic/vue';
</script>

<style scoped>
  .wrapper {
    display: flex;
    flex-wrap: wrap;

    align-items: center;
    justify-content: space-between;
    text-align: center;

    height: 300px;
    width: 300px;

    margin: 0 auto;
  }

  b {
    width: 100%;
  }

  .ripple-parent {
    position: relative;
    overflow: hidden;

    border: 1px solid #ddd;
  }

  .rectangle {
    width: 300px;
    height: 150px;
  }

  .rounded-rectangle {
    width: 185px;
    height: 65px;
    border-radius: 8px;
  }

  .circle {
    width: 90px;
    height: 90px;
    border-radius: 50%;
  }
</style>

Type

리플 효과에는 "bounded"와 "unbounded" 두 가지 타입이 있어요. 기본 타입인 "bounded"는 클릭 위치에서 바깥쪽으로 리플 효과가 퍼집니다. 항상 요소의 중앙에서 시작해 원형으로 퍼지는 리플 효과를 추가하려면 타입을 "unbounded"로 설정하세요.

JavaScript

<div class="wrapper">
  <b>Click on a shape to see the ripple</b>

  <div class="ion-activatable ripple-parent rounded-rectangle">
    Bounded
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent circle">
    Unbounded
    <ion-ripple-effect type="unbounded"></ion-ripple-effect>
  </div>
</div>

<style>
  .wrapper {
    display: flex;
    flex-wrap: wrap;

    align-items: center;
    justify-content: space-between;
    text-align: center;

    height: 170px;
    width: 400px;

    margin: 0 auto;
  }

  b {
    width: 100%;
  }

  .ripple-parent {
    display: flex;
    align-items: center;
    justify-content: center;

    position: relative;
    overflow: hidden;

    border: 1px solid #ddd;

    user-select: none;
  }

  .rounded-rectangle {
    width: 250px;
    height: 75px;
    border-radius: 8px;
  }

  .circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
  }
</style>

Angular

src/app/example.component.html

<div class="wrapper">
  <b>Click on a shape to see the ripple</b>

  <div class="ion-activatable ripple-parent rounded-rectangle">
    Bounded
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent circle">
    Unbounded
    <ion-ripple-effect type="unbounded"></ion-ripple-effect>
  </div>
</div>

src/app/example.component.css

.wrapper {
  display: flex;
  flex-wrap: wrap;

  align-items: center;
  justify-content: space-between;
  text-align: center;

  height: 170px;
  width: 400px;

  margin: 0 auto;
}

b {
  width: 100%;
}

.ripple-parent {
  display: flex;
  align-items: center;
  justify-content: center;

  position: relative;
  overflow: hidden;

  border: 1px solid #ddd;

  user-select: none;
}

.rounded-rectangle {
  width: 250px;
  height: 75px;
  border-radius: 8px;
}

.circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonRippleEffect } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonRippleEffect],
})
export class ExampleComponent {}

React

src/main.tsx

import React from 'react';
import { IonRippleEffect } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <div className="wrapper">
      <b>Click on a shape to see the ripple</b>

      <div className="ion-activatable ripple-parent rounded-rectangle">
        Bounded
        <IonRippleEffect></IonRippleEffect>
      </div>

      <div className="ion-activatable ripple-parent circle">
        Unbounded
        <IonRippleEffect type="unbounded"></IonRippleEffect>
      </div>
    </div>
  );
}
export default Example;

src/main.css

.wrapper {
  display: flex;
  flex-wrap: wrap;

  align-items: center;
  justify-content: space-between;
  text-align: center;

  height: 170px;
  width: 400px;

  margin: 0 auto;
}

b {
  width: 100%;
}

.ripple-parent {
  display: flex;
  align-items: center;
  justify-content: center;

  position: relative;
  overflow: hidden;

  border: 1px solid #ddd;

  user-select: none;
}

.rounded-rectangle {
  width: 250px;
  height: 75px;
  border-radius: 8px;
}

.circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

Vue

<template>
  <div class="wrapper">
    <b>Click on a shape to see the ripple</b>

    <div class="ion-activatable ripple-parent rounded-rectangle">
      Bounded
      <ion-ripple-effect></ion-ripple-effect>
    </div>

    <div class="ion-activatable ripple-parent circle">
      Unbounded
      <ion-ripple-effect type="unbounded"></ion-ripple-effect>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { IonRippleEffect } from '@ionic/vue';
</script>

<style scoped>
  .wrapper {
    display: flex;
    flex-wrap: wrap;

    align-items: center;
    justify-content: space-between;
    text-align: center;

    height: 170px;
    width: 400px;

    margin: 0 auto;
  }

  b {
    width: 100%;
  }

  .ripple-parent {
    display: flex;
    align-items: center;
    justify-content: center;

    position: relative;
    overflow: hidden;

    border: 1px solid #ddd;

    user-select: none;
  }

  .rounded-rectangle {
    width: 250px;
    height: 75px;
    border-radius: 8px;
  }

  .circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
  }
</style>

Customizing

리플은 CSS를 통해 다른 색으로 커스터마이즈할 수 있어요. 기본적으로 리플 색상은 텍스트 색상을 상속하며, 이는 일반적으로 바디 색상입니다. 부모 요소나 리플 효과 자체에 CSS color를 설정하면 이 색상을 바꿀 수 있어요.

JavaScript

<div class="wrapper">
  <b>Click on a shape to see the ripple</b>

  <div class="ion-activatable ripple-parent custom-parent">
    Custom Parent Color
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent">
    Custom Ripple Color
    <ion-ripple-effect class="custom-ripple"></ion-ripple-effect>
  </div>
</div>

<style>
  .wrapper {
    display: flex;
    flex-wrap: wrap;

    align-items: center;
    justify-content: space-between;
    text-align: center;

    height: 170px;
    width: 400px;

    margin: 0 auto;
  }

  b {
    width: 100%;
  }

  .ripple-parent {
    display: flex;
    align-items: center;
    justify-content: center;

    position: relative;
    overflow: hidden;

    border: 1px solid #ddd;

    user-select: none;

    width: 100%;
    height: 50px;
    border-radius: 8px;
  }

  .custom-parent {
    color: #de1e7e;
  }

  .custom-ripple {
    color: #501ace;
  }
</style>

Angular

src/app/example.component.html

<div class="wrapper">
  <b>Click on a shape to see the ripple</b>

  <div class="ion-activatable ripple-parent custom-parent">
    Custom Parent Color
    <ion-ripple-effect></ion-ripple-effect>
  </div>

  <div class="ion-activatable ripple-parent">
    Custom Ripple Color
    <ion-ripple-effect class="custom-ripple"></ion-ripple-effect>
  </div>
</div>

src/app/example.component.css

.wrapper {
  display: flex;
  flex-wrap: wrap;

  align-items: center;
  justify-content: space-between;
  text-align: center;

  height: 170px;
  width: 400px;

  margin: 0 auto;
}

b {
  width: 100%;
}

.ripple-parent {
  display: flex;
  align-items: center;
  justify-content: center;

  position: relative;
  overflow: hidden;

  border: 1px solid #ddd;

  user-select: none;

  width: 100%;
  height: 50px;
  border-radius: 8px;
}

.custom-parent {
  color: #de1e7e;
}

.custom-ripple {
  color: #501ace;
}

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonRippleEffect } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonRippleEffect],
})
export class ExampleComponent {}

React

src/main.tsx

import React from 'react';
import { IonRippleEffect } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <div className="wrapper">
      <b>Click on a shape to see the ripple</b>

      <div className="ion-activatable ripple-parent custom-parent">
        Custom Parent Color
        <IonRippleEffect></IonRippleEffect>
      </div>

      <div className="ion-activatable ripple-parent">
        Custom Ripple Color
        <IonRippleEffect className="custom-ripple"></IonRippleEffect>
      </div>
    </div>
  );
}
export default Example;

src/main.css

.wrapper {
  display: flex;
  flex-wrap: wrap;

  align-items: center;
  justify-content: space-between;
  text-align: center;

  height: 170px;
  width: 400px;

  margin: 0 auto;
}

b {
  width: 100%;
}

.ripple-parent {
  display: flex;
  align-items: center;
  justify-content: center;

  position: relative;
  overflow: hidden;

  border: 1px solid #ddd;

  user-select: none;

  width: 100%;
  height: 50px;
  border-radius: 8px;
}

.custom-parent {
  color: #de1e7e;
}

.custom-ripple {
  color: #501ace;
}

Vue

<template>
  <div class="wrapper">
    <b>Click on a shape to see the ripple</b>

    <div class="ion-activatable ripple-parent custom-parent">
      Custom Parent Color
      <ion-ripple-effect></ion-ripple-effect>
    </div>

    <div class="ion-activatable ripple-parent">
      Custom Ripple Color
      <ion-ripple-effect class="custom-ripple"></ion-ripple-effect>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { IonRippleEffect } from '@ionic/vue';
</script>

<style scoped>
  .wrapper {
    display: flex;
    flex-wrap: wrap;

    align-items: center;
    justify-content: space-between;
    text-align: center;

    height: 170px;
    width: 400px;

    margin: 0 auto;
  }

  b {
    width: 100%;
  }

  .ripple-parent {
    display: flex;
    align-items: center;
    justify-content: center;

    position: relative;
    overflow: hidden;

    border: 1px solid #ddd;

    user-select: none;

    width: 100%;
    height: 50px;
    border-radius: 8px;
  }

  .custom-parent {
    color: #de1e7e;
  }

  .custom-ripple {
    color: #501ace;
  }
</style>

Properties

type

Description: 리플 효과의 타입을 설정해요: - bounded: 사용자가 클릭한 위치에서 리플 효과가 퍼져 나갑니다 - unbounded: 리플 효과가 버튼의 중앙에서 퍼져 나가며 컨테이너를 넘쳐흐릅니다. 참고: bounded 리플의 표면(surface)은 overflow 프로퍼티를 hidden으로, unbounded 리플의 표면은 visible로 설정해야 해요.

Attribute: type

Type: "bounded" | "unbounded"

Default: 'bounded'

Events

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

Methods

addRipple

Description: 부모 요소에 리플 효과를 추가해요.

Signature: addRipple(x: number, y: number) => Promise<() => void>

Parameters: x: 리플이 시작될 가로 좌표예요. y: 리플이 시작될 세로 좌표예요.

CSS Shadow Parts

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

CSS Custom Properties

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

Slots

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

더 알아보기 (Learn more)

ion-ripple-effect는 탭하거나 클릭했을 때 물결이 퍼지는 Material 스타일의 피드백을 주는 컴포넌트예요. 부모에 ion-activatable 클래스를 붙이면 바로 동작하며, bounded/unbounded 타입과 CSS 색상으로 세부 효과까지 조절할 수 있어요.