Slackblocks.Color (slackblocks v2.8.0)

View Source

Attachment color conveniences. Returned binaries can be passed to Slackblocks.Attachment.

iex> Slackblocks.Color.hex!("A0B1c2")
"#A0B1c2"

iex> Slackblocks.Color.rgb!(0, 128, 255)
"#0080ff"

Summary

Functions

Validates six hex digits, with an optional # prefix; preserves letter case.

Like hex/1, raising on invalid input.

Resolves a semantic or named color atom: good, warning, danger, red, blue, yellow, green, orange, purple or black.

Like named/1, raising on invalid input.

Converts three integer channels in 0..255 to a lowercase hexadecimal color.

Like rgb/3, raising on invalid input.

Functions

hex(value)

@spec hex(binary()) :: {:ok, binary()} | {:error, Slackblocks.ValidationError.t()}

Validates six hex digits, with an optional # prefix; preserves letter case.

hex!(value)

@spec hex!(binary()) :: binary()

Like hex/1, raising on invalid input.

named(name)

@spec named(atom()) :: {:ok, binary()} | {:error, Slackblocks.ValidationError.t()}

Resolves a semantic or named color atom: good, warning, danger, red, blue, yellow, green, orange, purple or black.

named!(name)

@spec named!(atom()) :: binary()

Like named/1, raising on invalid input.

rgb(red, green, blue)

@spec rgb(integer(), integer(), integer()) ::
  {:ok, binary()} | {:error, Slackblocks.ValidationError.t()}

Converts three integer channels in 0..255 to a lowercase hexadecimal color.

rgb!(red, green, blue)

@spec rgb!(integer(), integer(), integer()) :: binary()

Like rgb/3, raising on invalid input.