scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
229 lines • 4.94 kB
JavaScript
import { AbsUITableCell } from "scriptable-abstract";
import { MockImage } from "../../media/image";
const DEFAULT_ON_TAP = () => {
};
class MockUITableCell extends AbsUITableCell {
constructor() {
super({
title: "",
subtitle: null,
titleColor: null,
subtitleColor: null,
titleFont: null,
subtitleFont: null,
widthWeight: 1,
image: null,
dismissOnTap: true,
onTap: DEFAULT_ON_TAP,
alignment: "left"
});
}
/**
* Title text of the cell
*/
get title() {
return this.state.title;
}
/**
* Sets the title text of the cell
*/
set title(value) {
if (typeof value !== "string") {
throw new Error("Title must be a string");
}
this.setState({ title: value });
}
/**
* Subtitle text of the cell
*/
get subtitle() {
return this.state.subtitle;
}
/**
* Sets the subtitle text of the cell
*/
set subtitle(value) {
if (value !== null && typeof value !== "string") {
throw new Error("Subtitle must be a string or null");
}
this.setState({ subtitle: value });
}
/**
* Color of the title text
*/
get titleColor() {
return this.state.titleColor;
}
/**
* Sets the color of the title text
*/
set titleColor(value) {
if (!value) {
throw new Error("Title color cannot be null");
}
this.setState({ titleColor: value });
}
/**
* Color of the subtitle text
*/
get subtitleColor() {
return this.state.subtitleColor;
}
/**
* Sets the color of the subtitle text
*/
set subtitleColor(value) {
if (!value) {
throw new Error("Subtitle color cannot be null");
}
this.setState({ subtitleColor: value });
}
/**
* Font of the title text
*/
get titleFont() {
return this.state.titleFont;
}
/**
* Sets the font of the title text
*/
set titleFont(value) {
if (!value) {
throw new Error("Title font cannot be null");
}
this.setState({ titleFont: value });
}
/**
* Font of the subtitle text
*/
get subtitleFont() {
return this.state.subtitleFont;
}
/**
* Sets the font of the subtitle text
*/
set subtitleFont(value) {
if (!value) {
throw new Error("Subtitle font cannot be null");
}
this.setState({ subtitleFont: value });
}
/**
* Width weight of the cell
*/
get widthWeight() {
return this.state.widthWeight;
}
/**
* Sets the width weight of the cell
*/
set widthWeight(value) {
if (typeof value !== "number" || value <= 0) {
throw new Error("Width weight must be a positive number");
}
this.setState({ widthWeight: value });
}
/**
* Image of the cell
*/
get image() {
return this.state.image;
}
/**
* Sets the image of the cell
*/
set image(value) {
if (!value) {
throw new Error("Image cannot be null");
}
this.setState({ image: value });
}
/**
* Whether to dismiss the table when the cell is tapped
*/
get dismissOnTap() {
return this.state.dismissOnTap;
}
/**
* Sets whether to dismiss the table when the cell is tapped
*/
set dismissOnTap(value) {
if (typeof value !== "boolean") {
throw new Error("DismissOnTap must be a boolean");
}
this.setState({ dismissOnTap: value });
}
/**
* Function to call when the cell is tapped
*/
get onTap() {
return this.state.onTap;
}
/**
* Sets the function to call when the cell is tapped
*/
set onTap(value) {
if (typeof value !== "function") {
throw new Error("OnTap must be a function");
}
this.setState({ onTap: value });
}
/**
* Left aligns the content of the cell
*/
leftAligned() {
this.setState({ alignment: "left" });
}
/**
* Right aligns the content of the cell
*/
rightAligned() {
this.setState({ alignment: "right" });
}
/**
* Center aligns the content of the cell
*/
centerAligned() {
this.setState({ alignment: "center" });
}
static text(title, subtitle) {
const cell = new MockUITableCell();
if (title !== void 0) {
cell.title = title;
}
if (subtitle !== void 0) {
cell.subtitle = subtitle;
}
return cell;
}
static image(image) {
if (!image) {
throw new Error("Image cannot be null");
}
const cell = new MockUITableCell();
cell.image = image;
return cell;
}
static imageAtURL(url) {
if (!url) {
throw new Error("URL cannot be empty");
}
const cell = new MockUITableCell();
const image = MockImage.fromFile(url);
cell.image = image;
return cell;
}
static button(title) {
if (!title) {
throw new Error("Button title cannot be empty");
}
const cell = new MockUITableCell();
cell.title = title;
cell.centerAligned();
return cell;
}
}
export {
MockUITableCell
};
//# sourceMappingURL=ui-table-cell.js.map