Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fun Popover(
show = show,
onDismissRequest = onDismissRequest,
triggerInfo = { triggerInfo },
shape = style.shape,
shape = style.shapes,
shadow = style.shadow,
dimensions = style.dimensions,
colors = style.colors,
Expand Down Expand Up @@ -145,7 +145,7 @@ fun Popover(
show = show,
onDismissRequest = onDismissRequest,
triggerInfo = { triggerInfo },
shape = style.shape,
shape = style.shapes,
shadow = style.shadow,
dimensions = style.dimensions,
colors = style.colors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.sdds.api.info.compose.ApiInfo
import com.sdds.compose.uikit.graphics.brush.asStatefulBrush
import com.sdds.compose.uikit.interactions.InteractiveColor
import com.sdds.compose.uikit.interactions.StatefulValue
import com.sdds.compose.uikit.interactions.asStatefulBrush
import com.sdds.compose.uikit.interactions.asStatefulValue
import com.sdds.compose.uikit.shadow.ShadowAppearance
import com.sdds.compose.uikit.style.Style
Expand All @@ -31,8 +34,14 @@ interface PopoverStyle : Style {
/**
* Форма компонента
*/
@Deprecated("use shapes", replaceWith = ReplaceWith("shapes"))
val shape: CornerBasedShape

/**
* Формы компонента
*/
val shapes: StatefulValue<CornerBasedShape>

/**
* Тень компонента
*/
Expand Down Expand Up @@ -65,7 +74,13 @@ interface PopoverStyleBuilder : StyleBuilder<PopoverStyle> {
/**
* Устанавливает форму [shape] компонента
*/
fun shape(shape: CornerBasedShape): PopoverStyleBuilder
fun shape(shape: CornerBasedShape): PopoverStyleBuilder =
shape(shape.asStatefulValue())

/**
* Устанавливает форму [shape] компонента
*/
fun shape(shape: StatefulValue<CornerBasedShape>): PopoverStyleBuilder

/**
* Устанавливает тень [shadow] компонента
Expand All @@ -86,20 +101,22 @@ interface PopoverStyleBuilder : StyleBuilder<PopoverStyle> {
}

private class DefaultPopoverStyle(
override val shape: CornerBasedShape,
override val shapes: StatefulValue<CornerBasedShape>,
override val shadow: ShadowAppearance,
override val dimensions: PopoverDimensions,
override val colors: PopoverColors,
) : PopoverStyle {

@Deprecated("use shapes", replaceWith = ReplaceWith("shapes"))
override val shape: CornerBasedShape = shapes.getDefaultValue()
class Builder : PopoverStyleBuilder {
private var shape: CornerBasedShape? = null
private var shapes: StatefulValue<CornerBasedShape>? = null
private var shadow: ShadowAppearance? = null
private val colorsBuilder = PopoverColors.builder()
private val dimensionsBuilder = PopoverDimensions.builder()

override fun shape(shape: CornerBasedShape) = apply {
this.shape = shape
override fun shape(shape: StatefulValue<CornerBasedShape>) = apply {
this.shapes = shape
}

override fun shadow(shadow: ShadowAppearance) = apply {
Expand All @@ -119,7 +136,7 @@ private class DefaultPopoverStyle(

override fun style(): PopoverStyle {
return DefaultPopoverStyle(
shape = shape ?: RoundedCornerShape(15),
shapes = shapes ?: RoundedCornerShape(15).asStatefulValue(),
shadow = shadow ?: ShadowAppearance(),
colors = colorsBuilder.build(),
dimensions = dimensionsBuilder.build(),
Expand Down Expand Up @@ -152,6 +169,19 @@ interface PopoverColors {
* Builder для [PopoverColors]
*/
interface PopoverColorsBuilder {

/**
* Устанавливает фон [backgroundColor] компонента.
*/
fun backgroundColor(backgroundColor: Color): PopoverColorsBuilder =
backgroundColor(backgroundColor.asStatefulBrush())

/**
* Устанавливает фон [backgroundColor] компонента.
*/
fun backgroundColor(backgroundColor: InteractiveColor): PopoverColorsBuilder =
backgroundColor(backgroundColor.asStatefulBrush())

/**
* Устанавливает фон [backgroundColor] компонента.
*/
Expand Down Expand Up @@ -198,28 +228,58 @@ interface PopoverDimensions {
/**
* Минимальная ширина компонента
*/
@Deprecated("use widthValues", replaceWith = ReplaceWith("widthValues"))
val width: Dp

/**
* Минимальная ширина компонента
*/
val widthValues: StatefulValue<Dp>

/**
* Отступ до компонента
*/
@Deprecated("use offsetValues", replaceWith = ReplaceWith("offsetValues"))
val offset: Dp

/**
* Отступ до компонента
*/
val offsetValues: StatefulValue<Dp>

/**
* Ширина указателя
*/
@Deprecated("use tailWidthValues", replaceWith = ReplaceWith("tailWidthValues"))
val tailWidth: Dp

/**
* Ширина указателя
*/
val tailWidthValues: StatefulValue<Dp>

/**
* Высота указателя
*/
@Deprecated("use tailHeightValues", replaceWith = ReplaceWith("tailHeightValues"))
val tailHeight: Dp

/**
* Высота указателя
*/
val tailHeightValues: StatefulValue<Dp>

/**
* Отступ указателя
*/
@Deprecated("use tailPaddingValues", replaceWith = ReplaceWith("tailPaddingValues"))
val tailPadding: Dp

/**
* Отступ указателя
*/
val tailPaddingValues: StatefulValue<Dp>

companion object {
/**
* Создает экземпляр [PopoverDimensionsBuilder]
Expand All @@ -235,27 +295,52 @@ interface PopoverDimensionsBuilder {
/**
* Устанавливает минимальную ширину [width] компонента.
*/
fun width(width: Dp): PopoverDimensionsBuilder
fun width(width: Dp): PopoverDimensionsBuilder = width(width.asStatefulValue())

/**
* Устанавливает минимальную ширину [width] компонента.
*/
fun width(width: StatefulValue<Dp>): PopoverDimensionsBuilder

/**
* Устанавливает смещение [offset] компонента относительно триггера.
*/
fun offset(offset: Dp): PopoverDimensionsBuilder
fun offset(offset: Dp): PopoverDimensionsBuilder = offset(offset.asStatefulValue())

/**
* Устанавливает смещение [offset] компонента относительно триггера.
*/
fun offset(offset: StatefulValue<Dp>): PopoverDimensionsBuilder

/**
* Устанавливает ширину [tailWidth] указателя.
*/
fun tailWidth(tailWidth: Dp): PopoverDimensionsBuilder = tailWidth(tailWidth.asStatefulValue())

/**
* Устанавливает ширину [tailWidth] указателя.
*/
fun tailWidth(tailWidth: Dp): PopoverDimensionsBuilder
fun tailWidth(tailWidth: StatefulValue<Dp>): PopoverDimensionsBuilder

/**
* Устанавливает высоту [tailHeight] указателя.
*/
fun tailHeight(tailHeight: Dp): PopoverDimensionsBuilder = tailHeight(tailHeight.asStatefulValue())

/**
* Устанавливает высоту [tailHeight] указателя.
*/
fun tailHeight(tailHeight: Dp): PopoverDimensionsBuilder
fun tailHeight(tailHeight: StatefulValue<Dp>): PopoverDimensionsBuilder

/**
* Устанавливает отступ [tailPadding] указателя относительно края компонента.
*/
fun tailPadding(tailPadding: Dp): PopoverDimensionsBuilder
fun tailPadding(tailPadding: Dp): PopoverDimensionsBuilder = tailPadding(tailPadding.asStatefulValue())

/**
* Устанавливает отступ [tailPadding] указателя относительно края компонента.
*/
fun tailPadding(tailPadding: StatefulValue<Dp>): PopoverDimensionsBuilder

/**
* Создает экземпляр [PopoverDimensions]
Expand All @@ -264,48 +349,63 @@ interface PopoverDimensionsBuilder {
}

private class DefaultPopoverDimensions(
override val width: Dp,
override val offset: Dp,
override val tailWidth: Dp,
override val tailHeight: Dp,
override val tailPadding: Dp,
override val widthValues: StatefulValue<Dp>,
override val offsetValues: StatefulValue<Dp>,
override val tailWidthValues: StatefulValue<Dp>,
override val tailHeightValues: StatefulValue<Dp>,
override val tailPaddingValues: StatefulValue<Dp>,

) : PopoverDimensions {
@Deprecated("use widthValues", replaceWith = ReplaceWith("widthValues"))
override val width: Dp = widthValues.getDefaultValue()

@Deprecated("use offsetValues", replaceWith = ReplaceWith("offsetValues"))
override val offset: Dp = offsetValues.getDefaultValue()

@Deprecated("use tailWidthValues", replaceWith = ReplaceWith("tailWidthValues"))
override val tailWidth: Dp = tailWidthValues.getDefaultValue()

@Deprecated("use tailHeightValues", replaceWith = ReplaceWith("tailHeightValues"))
override val tailHeight: Dp = tailHeightValues.getDefaultValue()

@Deprecated("use tailPaddingValues", replaceWith = ReplaceWith("tailPaddingValues"))
override val tailPadding: Dp = tailPaddingValues.getDefaultValue()

class Builder : PopoverDimensionsBuilder {

private var width: Dp? = null
private var offset: Dp? = null
private var tailWidth: Dp? = null
private var tailHeight: Dp? = null
private var tailPadding: Dp? = null
private var width: StatefulValue<Dp>? = null
private var offset: StatefulValue<Dp>? = null
private var tailWidth: StatefulValue<Dp>? = null
private var tailHeight: StatefulValue<Dp>? = null
private var tailPadding: StatefulValue<Dp>? = null

override fun width(width: Dp) = apply {
override fun width(width: StatefulValue<Dp>) = apply {
this.width = width
}

override fun offset(offset: Dp) = apply {
override fun offset(offset: StatefulValue<Dp>) = apply {
this.offset = offset
}

override fun tailWidth(tailWidth: Dp) = apply {
override fun tailWidth(tailWidth: StatefulValue<Dp>) = apply {
this.tailWidth = tailWidth
}

override fun tailHeight(tailHeight: Dp) = apply {
override fun tailHeight(tailHeight: StatefulValue<Dp>) = apply {
this.tailHeight = tailHeight
}

override fun tailPadding(tailPadding: Dp) = apply {
override fun tailPadding(tailPadding: StatefulValue<Dp>) = apply {
this.tailPadding = tailPadding
}

override fun build(): PopoverDimensions {
return DefaultPopoverDimensions(
width = width ?: 40.dp,
offset = offset ?: 0.dp,
tailWidth = tailWidth ?: 20.dp,
tailHeight = tailHeight ?: 8.dp,
tailPadding = tailPadding ?: 10.dp,
widthValues = width ?: 40.dp.asStatefulValue(),
offsetValues = offset ?: 0.dp.asStatefulValue(),
tailWidthValues = tailWidth ?: 20.dp.asStatefulValue(),
tailHeightValues = tailHeight ?: 8.dp.asStatefulValue(),
tailPaddingValues = tailPadding ?: 10.dp.asStatefulValue(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.PopupProperties
import com.sdds.compose.uikit.interactions.asStatefulValue
import com.sdds.compose.uikit.interactions.getValue
import com.sdds.compose.uikit.internal.common.StyledText
import com.sdds.compose.uikit.internal.popover.BasePopover
Expand Down Expand Up @@ -75,7 +76,7 @@ fun Tooltip(
triggerInfo = triggerInfo,
dimensions = style.dimensions.toPopoverDimensions(),
colors = style.colors.toPopoverColors(),
shape = style.shape,
shape = style.shape.asStatefulValue(),
shadow = style.shadow,
placement = placement,
placementMode = placementMode,
Expand Down Expand Up @@ -121,11 +122,25 @@ fun Tooltip(

private fun TooltipDimensions.toPopoverDimensions(offset: Dp = this.offset): PopoverDimensions {
return object : PopoverDimensions {
override val width = 0.dp
override val offset = offset
override val tailWidth = this@toPopoverDimensions.tailWidth
override val tailHeight = this@toPopoverDimensions.tailHeight
override val tailPadding = this@toPopoverDimensions.tailPadding
@Deprecated("use widthValues", replaceWith = ReplaceWith("widthValues"))
override val width: Dp = 0.dp
override val widthValues = width.asStatefulValue()

@Deprecated("use offsetValues", replaceWith = ReplaceWith("offsetValues"))
override val offset: Dp = offset
override val offsetValues = this.offset.asStatefulValue()

@Deprecated("use tailWidthValues", replaceWith = ReplaceWith("tailWidthValues"))
override val tailWidth: Dp = this@toPopoverDimensions.tailWidth
override val tailWidthValues = this.tailWidth.asStatefulValue()

@Deprecated("use tailHeightValues", replaceWith = ReplaceWith("tailHeightValues"))
override val tailHeight: Dp = this@toPopoverDimensions.tailHeight
override val tailHeightValues = this.tailHeight.asStatefulValue()

@Deprecated("use tailPaddingValues", replaceWith = ReplaceWith("tailPaddingValues"))
override val tailPadding: Dp = this@toPopoverDimensions.tailPadding
override val tailPaddingValues = this.tailPadding.asStatefulValue()
}
}

Expand Down
Loading
Loading