Color Picker in OpenHarmony
Install using npm
npm i @ohos/colorpicker
Details about OpenHarmony NPM environment configuration, see at here
- Import files and code dependencies
import { colorPicker } from '@ohos/colorpicker'
- Initialize ColorPicker model data
private model: colorPicker.Model = new colorPicker.Model()
- Code for creating ColorPicker Screen
private model: colorPicker.Model = new colorPicker.Model()
build() {
Column() {
colorPicker({ model: this.model })
}
}
- Code for creating colorDialog Screen
dialogController: CustomDialogController = new CustomDialogController({
builder: colorDialog({ action: (value) => this.onAccept(value) }),
cancel: this.existApp,
autoCancel: true,
alignment: DialogAlignment.Bottom,
});
onAccept(value: number) {
this.hue = value;
var RGBPixels = this.HSLToRGB(this.hue, this.SliderSaturation, this.SliderLightness)
var HEXCode = this.rgbToHex(RGBPixels[0], RGBPixels[1], RGBPixels[2])
}
existApp() {
this.OpacityofScreen = 1
console.log("Cancel dialog!");
}
-
Use the button Color Picker to open the ColorPicker Screen .
-
In ColorPicker Screen, use button Selection of Color to open the customDialog and choose the main color.
-
Use the button Change Saturation and Lightness to change the saturation and lightness of the main color and choose any variation of it.
-
HEX-Code of the selected color will be upddated on the screen.
|---- ColorPicker (Project Name)
| |---- color_picker (Color Picker Library)
| |---- src
| |---- main
| |---- ets
| |----components
| |---- MainPage
| |---- colorDialog.ets
| |---- colorPicker.ets
| |---- index.ets
|
| |---- entry
| |---- src
| |---- main
| |---- ets
| |----pages
| |---- colorPickerUI.ets
| |---- index.ets
Supports OpenHarmony API version 8 or above
If you find any problems during usage, you can submit an Issue to us. Of course, we also welcome you to send us PR.
This project is based on Apache License 2.0, please enjoy and participate in open source freely.
Design by: Ayush