Skip to content

Commit

Permalink
[#677] Review: Restrict header image type with a sealed interface
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea authored and florentmaitre committed Nov 8, 2023
1 parent f468cf6 commit ea44188
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/components/NavigationDrawers.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Parameter | Default value | Description
Parameter | Default value | Description
-- | -- | --
<b>`title: String`</b> | | Title displayed in the header
`image: OdsComponentImage<Nothing>?` | `null` | Image displayed in the header. It should be an avatar image of `OdsModalDrawerHeaderAvatar` type or a background image of `OdsModalDrawerHeaderBackground` type. <b>Note that other component images will not be taken into account.</b>
`image: OdsModalDrawerHeaderImage?` | `null` | Image displayed in the header. It should be an avatar image of `OdsModalDrawerHeaderAvatar` type or a background image of `OdsModalDrawerHeaderBackground` type.
`subtitle: String?` | `null` | Subtitle displayed below the `title` in the header
{:.table}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ data class OdsModalDrawerListItem(
*
* @property title Title displayed in the header.
* @property image Image displayed in the header. It should be an avatar image of type [OdsModalDrawerHeaderAvatar] or a background image
* of type [OdsModalDrawerHeaderBackground]. Note that other component images will not be taken into account.
* of type [OdsModalDrawerHeaderBackground].
* @property subtitle Subtitle displayed below the [title] in the header.
*/
class OdsModalDrawerHeader(
private var title: String,
private val image: OdsComponentImage<Nothing>? = null,
private val image: OdsModalDrawerHeaderImage? = null,
private var subtitle: String? = null
) : OdsComponentContent<Nothing>() {

Expand Down Expand Up @@ -228,10 +228,15 @@ class OdsModalDrawerHeader(

}

/**
* An image that can be added in the [OdsModalDrawerHeader].
*/
sealed interface OdsModalDrawerHeaderImage

/**
* An avatar in [OdsModalDrawerHeader].
*/
class OdsModalDrawerHeaderAvatar : OdsComponentCircularImage {
class OdsModalDrawerHeaderAvatar : OdsModalDrawerHeaderImage, OdsComponentCircularImage {

/**
* Creates an instance of [OdsModalDrawerHeaderAvatar].
Expand Down Expand Up @@ -261,7 +266,7 @@ class OdsModalDrawerHeaderAvatar : OdsComponentCircularImage {
/**
* A background image in the [OdsModalDrawerHeader].
*/
class OdsModalDrawerHeaderBackground : OdsComponentImage<Nothing> {
class OdsModalDrawerHeaderBackground : OdsModalDrawerHeaderImage, OdsComponentImage<Nothing> {

/**
* Creates an instance of [OdsModalDrawerHeaderBackground].
Expand Down

0 comments on commit ea44188

Please sign in to comment.