Skip to content

An open source design system that's fully customizable and agent ready

TypeScript
5.8 KB
Raw Blame
// Generated by @astryxdesign/native. Do not edit.
public enum ButtonVariant: String, CaseIterable, Codable, Sendable {
  case primary = "primary"
  case secondary = "secondary"
  case ghost = "ghost"
  case destructive = "destructive"
}
public enum ButtonSize: String, CaseIterable, Codable, Sendable {
  case sm = "sm"
  case md = "md"
  case lg = "lg"
}
public enum ButtonElevation: String, CaseIterable, Codable, Sendable {
  case none = "none"
  case low = "low"
  case med = "med"
  case high = "high"
}
public enum ButtonWidth: String, CaseIterable, Codable, Sendable {
  case content = "content"
  case fill = "fill"
}
#if os(iOS)
public struct ButtonProps {
  /// Base props attach to this part on every platform.
  public static let baseTarget: AstryxBaseTarget = .root
  public var base: AstryxBaseProps
  public var label: String
  public var variant: ButtonVariant?
  public var size: ButtonSize?
  public var elevation: ButtonElevation?
  public var isLoading: Bool?
  public var isInterruptible: Bool?
  public var isDisabled: Bool?
  public var width: ButtonWidth?
  public var tooltip: String?
  public var onClick: (() -> Void)?
  public var href: String?
  public init(label: String, variant: ButtonVariant? = nil, size: ButtonSize? = nil, elevation: ButtonElevation? = nil, isLoading: Bool? = nil, isInterruptible: Bool? = nil, isDisabled: Bool? = nil, width: ButtonWidth? = nil, tooltip: String? = nil, onClick: (() -> Void)? = nil, href: String? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
    self.label = label
    self.variant = variant
    self.size = size
    self.elevation = elevation
    self.isLoading = isLoading
    self.isInterruptible = isInterruptible
    self.isDisabled = isDisabled
    self.width = width
    self.tooltip = tooltip
    self.onClick = onClick
    self.href = href
    self.base = base
  }
}
public struct ButtonNode: Decodable, Equatable, Sendable {
  public struct Props: Decodable, Equatable, Sendable {
    public var label: String
    public var variant: ButtonVariant?
    public var size: ButtonSize?
    public var elevation: ButtonElevation?
    public var isLoading: Bool?
    public var isInterruptible: Bool?
    public var isDisabled: Bool?
    public var width: ButtonWidth?
    public var tooltip: String?
    public var href: String?
  }
  public let key: String
  public let base: AstryxBaseProps?
  public let props: Props
  /// The callbacks the core listens to, by prop name.
  public let events: [String]?

  public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }

  /// The contract a Button view takes; its callbacks send actions to the core.
  public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ButtonProps {
    let key = self.key
    return ButtonProps(
      label: props.label,
      variant: props.variant,
      size: props.size,
      elevation: props.elevation,
      isLoading: props.isLoading,
      isInterruptible: props.isInterruptible,
      isDisabled: props.isDisabled,
      width: props.width,
      tooltip: props.tooltip,
      onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "Button", event: "onClick", args: [])) } : nil,
      href: props.href,
      base: base ?? AstryxBaseProps()
    )
  }
}
#endif
#if os(macOS)
public struct ButtonProps {
  /// Base props attach to this part on every platform.
  public static let baseTarget: AstryxBaseTarget = .root
  public var base: AstryxBaseProps
  public var label: String
  public var variant: ButtonVariant?
  public var size: ButtonSize?
  public var elevation: ButtonElevation?
  public var isLoading: Bool?
  public var isInterruptible: Bool?
  public var isDisabled: Bool?
  public var width: ButtonWidth?
  public var tooltip: String?
  public var onClick: (() -> Void)?
  public var href: String?
  public init(label: String, variant: ButtonVariant? = nil, size: ButtonSize? = nil, elevation: ButtonElevation? = nil, isLoading: Bool? = nil, isInterruptible: Bool? = nil, isDisabled: Bool? = nil, width: ButtonWidth? = nil, tooltip: String? = nil, onClick: (() -> Void)? = nil, href: String? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
    self.label = label
    self.variant = variant
    self.size = size
    self.elevation = elevation
    self.isLoading = isLoading
    self.isInterruptible = isInterruptible
    self.isDisabled = isDisabled
    self.width = width
    self.tooltip = tooltip
    self.onClick = onClick
    self.href = href
    self.base = base
  }
}
public struct ButtonNode: Decodable, Equatable, Sendable {
  public struct Props: Decodable, Equatable, Sendable {
    public var label: String
    public var variant: ButtonVariant?
    public var size: ButtonSize?
    public var elevation: ButtonElevation?
    public var isLoading: Bool?
    public var isInterruptible: Bool?
    public var isDisabled: Bool?
    public var width: ButtonWidth?
    public var tooltip: String?
    public var href: String?
  }
  public let key: String
  public let base: AstryxBaseProps?
  public let props: Props
  /// The callbacks the core listens to, by prop name.
  public let events: [String]?

  public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }

  /// The contract a Button view takes; its callbacks send actions to the core.
  public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ButtonProps {
    let key = self.key
    return ButtonProps(
      label: props.label,
      variant: props.variant,
      size: props.size,
      elevation: props.elevation,
      isLoading: props.isLoading,
      isInterruptible: props.isInterruptible,
      isDisabled: props.isDisabled,
      width: props.width,
      tooltip: props.tooltip,
      onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "Button", event: "onClick", args: [])) } : nil,
      href: props.href,
      base: base ?? AstryxBaseProps()
    )
  }
}
#endif