Skip to content

Commit e252b09

Browse files
jamipouchiMiquel Puig Turongithub-actions[bot]
authored
[NEUT-1872] Rename SponsoredBanner to InsetBanner (#1763)
* [NEUT-1872] Rename SponsoredBanner to InsetBanner * [NEUT-1872] Fix, add deleted internal file * Updated snapshots for 'dm' * Updated snapshots for 'default' * Updated snapshots for 'rtl' * Trigger CI --------- Co-authored-by: Miquel Puig Turon <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 4456e11 commit e252b09

File tree

61 files changed

+315
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+315
-315
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Backpack for Android - Skyscanner's Design System
3+
*
4+
* Copyright 2018 Skyscanner Ltd
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package net.skyscanner.backpack.compose.insetbanner
20+
21+
import net.skyscanner.backpack.compose.BpkSnapshotTest
22+
import net.skyscanner.backpack.demo.compose.InsetBannerStoryOnDark
23+
import net.skyscanner.backpack.demo.compose.InsetBannerStoryOnLight
24+
import net.skyscanner.backpack.demo.compose.InsetBannerStoryWithoutCTA
25+
import net.skyscanner.backpack.demo.compose.InsetBannerStoryWithoutSubHeadline
26+
import net.skyscanner.backpack.demo.compose.InsetBannerStoryWithoutTitle
27+
import net.skyscanner.backpack.demo.compose.InsetBannerStoryWithoutTitleAndSubHeadline
28+
import org.junit.Test
29+
30+
class BpkInsetBannerTest : BpkSnapshotTest() {
31+
32+
@Test
33+
fun defaultOnDark() = snap {
34+
InsetBannerStoryOnDark()
35+
}
36+
37+
@Test
38+
fun defaultOnLight() = snap {
39+
InsetBannerStoryOnLight()
40+
}
41+
42+
@Test
43+
fun insetBannerWithoutSubheadline() = snap {
44+
InsetBannerStoryWithoutSubHeadline()
45+
}
46+
47+
@Test
48+
fun insetBannerWithoutTitle() = snap {
49+
InsetBannerStoryWithoutTitle()
50+
}
51+
52+
@Test
53+
fun insetBannerWithoutTitleAndSubheadline() = snap {
54+
InsetBannerStoryWithoutTitleAndSubHeadline()
55+
}
56+
57+
@Test
58+
fun insetBannerWithoutCallToAction() = snap {
59+
InsetBannerStoryWithoutCTA()
60+
}
61+
}

app/src/androidTest/java/net/skyscanner/backpack/compose/sponsoredbanner/BpkSponsoredBannerTest.kt

-61
This file was deleted.

app/src/main/java/net/skyscanner/backpack/demo/components/SponsoredBannerComponent.kt app/src/main/java/net/skyscanner/backpack/demo/components/InsetBannerComponent.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ package net.skyscanner.backpack.demo.components
2020

2121
import net.skyscanner.backpack.meta.ComponentMarker
2222

23-
@ComponentMarker("Sponsored Banner")
24-
annotation class SponsoredBannerComponent
23+
@ComponentMarker("Inset Banner")
24+
annotation class InsetBannerComponent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/**
2+
* Backpack for Android - Skyscanner's Design System
3+
*
4+
* Copyright 2018 Skyscanner Ltd
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package net.skyscanner.backpack.demo.compose
20+
21+
import androidx.compose.foundation.Image
22+
import androidx.compose.foundation.layout.Box
23+
import androidx.compose.foundation.layout.padding
24+
import androidx.compose.runtime.Composable
25+
import androidx.compose.ui.Modifier
26+
import androidx.compose.ui.graphics.Color
27+
import androidx.compose.ui.layout.ContentScale
28+
import androidx.compose.ui.res.painterResource
29+
import androidx.compose.ui.res.stringResource
30+
import net.skyscanner.backpack.compose.insetbanner.BpkInsetBanner
31+
import net.skyscanner.backpack.compose.insetbanner.BpkInsetBannerCTA
32+
import net.skyscanner.backpack.compose.insetbanner.BpkInsetBannerVariant
33+
import net.skyscanner.backpack.compose.insetbanner.BpkInsetBannerVariant.OnDark
34+
import net.skyscanner.backpack.compose.insetbanner.BpkInsetBannerVariant.OnLight
35+
import net.skyscanner.backpack.compose.tokens.BpkSpacing
36+
import net.skyscanner.backpack.demo.R
37+
import net.skyscanner.backpack.demo.components.InsetBannerComponent
38+
import net.skyscanner.backpack.demo.meta.ComposeStory
39+
40+
@Composable
41+
@InsetBannerComponent
42+
@ComposeStory("OnLight")
43+
fun InsetBannerStoryOnLight() {
44+
DefaultInsetBannerSample(
45+
variant = OnLight,
46+
title = stringResource(R.string.inset_banner_title),
47+
subHeadline = stringResource(R.string.inset_banner_sub_headline),
48+
callToAction = BpkInsetBannerCTA(
49+
stringResource(R.string.inset_banner_cta_text),
50+
stringResource(R.string.inset_banner_cta_accessibility_label),
51+
),
52+
body = stringResource(R.string.inset_banner_body),
53+
logo = getPartnerLogo(variant = OnLight),
54+
)
55+
}
56+
57+
@Composable
58+
@InsetBannerComponent
59+
@ComposeStory("OnDark")
60+
fun InsetBannerStoryOnDark() {
61+
DefaultInsetBannerSample(
62+
variant = OnDark,
63+
title = stringResource(R.string.inset_banner_title),
64+
subHeadline = stringResource(R.string.inset_banner_sub_headline),
65+
callToAction = BpkInsetBannerCTA(
66+
stringResource(R.string.inset_banner_cta_text),
67+
stringResource(R.string.inset_banner_cta_accessibility_label),
68+
),
69+
body = stringResource(R.string.inset_banner_body),
70+
logo = getPartnerLogo(variant = OnDark),
71+
)
72+
}
73+
74+
@Composable
75+
@InsetBannerComponent
76+
@ComposeStory("Without Title")
77+
fun InsetBannerStoryWithoutTitle(modifier: Modifier = Modifier) {
78+
DefaultInsetBannerSample(
79+
variant = OnDark,
80+
subHeadline = stringResource(R.string.inset_banner_sub_headline),
81+
callToAction = BpkInsetBannerCTA(
82+
stringResource(R.string.inset_banner_cta_text),
83+
stringResource(R.string.inset_banner_cta_accessibility_label),
84+
),
85+
body = stringResource(R.string.inset_banner_body),
86+
logo = getPartnerLogo(variant = OnDark),
87+
)
88+
}
89+
90+
@Composable
91+
@InsetBannerComponent
92+
@ComposeStory("Without subHeadline")
93+
fun InsetBannerStoryWithoutSubHeadline(modifier: Modifier = Modifier) {
94+
DefaultInsetBannerSample(
95+
variant = OnDark,
96+
title = stringResource(R.string.inset_banner_title),
97+
callToAction = BpkInsetBannerCTA(
98+
stringResource(R.string.inset_banner_cta_text),
99+
stringResource(R.string.inset_banner_cta_accessibility_label),
100+
),
101+
body = stringResource(R.string.inset_banner_body),
102+
logo = getPartnerLogo(variant = OnDark),
103+
)
104+
}
105+
106+
@Composable
107+
@InsetBannerComponent
108+
@ComposeStory("Without Title and subHeadline")
109+
fun InsetBannerStoryWithoutTitleAndSubHeadline(modifier: Modifier = Modifier) {
110+
DefaultInsetBannerSample(
111+
variant = OnDark,
112+
callToAction = BpkInsetBannerCTA(
113+
stringResource(R.string.inset_banner_cta_text),
114+
stringResource(R.string.inset_banner_cta_accessibility_label),
115+
),
116+
body = stringResource(R.string.inset_banner_body),
117+
logo = getPartnerLogo(variant = OnDark),
118+
)
119+
}
120+
121+
@Composable
122+
@InsetBannerComponent
123+
@ComposeStory("Without CTA")
124+
fun InsetBannerStoryWithoutCTA(modifier: Modifier = Modifier) {
125+
DefaultInsetBannerSample(
126+
variant = OnDark,
127+
title = stringResource(R.string.inset_banner_title),
128+
subHeadline = stringResource(R.string.inset_banner_sub_headline),
129+
body = stringResource(R.string.inset_banner_body),
130+
logo = getPartnerLogo(variant = OnDark),
131+
)
132+
}
133+
134+
@Composable
135+
@InsetBannerComponent
136+
@ComposeStory("Without Body")
137+
fun InsetBannerStoryWithoutBody(modifier: Modifier = Modifier) {
138+
DefaultInsetBannerSample(
139+
variant = OnDark,
140+
title = stringResource(R.string.inset_banner_title),
141+
subHeadline = stringResource(R.string.inset_banner_sub_headline),
142+
callToAction = BpkInsetBannerCTA(
143+
stringResource(R.string.inset_banner_cta_text),
144+
stringResource(R.string.inset_banner_cta_accessibility_label),
145+
),
146+
logo = getPartnerLogo(variant = OnDark),
147+
)
148+
}
149+
150+
@Composable
151+
@InsetBannerComponent
152+
@ComposeStory("Without Logo")
153+
fun InsetBannerStoryWithoutLogo(modifier: Modifier = Modifier) {
154+
DefaultInsetBannerSample(
155+
variant = OnDark,
156+
title = stringResource(R.string.inset_banner_title),
157+
subHeadline = stringResource(R.string.inset_banner_sub_headline),
158+
callToAction = BpkInsetBannerCTA(
159+
stringResource(R.string.inset_banner_cta_text),
160+
stringResource(R.string.inset_banner_cta_accessibility_label),
161+
),
162+
body = stringResource(R.string.inset_banner_body),
163+
logo = null,
164+
)
165+
}
166+
167+
@Composable
168+
private fun getPartnerLogo(variant: BpkInsetBannerVariant): @Composable () -> Unit = {
169+
Image(
170+
painter = when (variant) {
171+
OnDark -> painterResource(R.drawable.inset_banner_skyland_white)
172+
OnLight -> painterResource(R.drawable.inset_banner_skyland_black)
173+
},
174+
contentDescription = stringResource(R.string.inset_banner_cta_accessibility_label),
175+
contentScale = ContentScale.Fit,
176+
)
177+
}
178+
179+
@Composable
180+
internal fun DefaultInsetBannerSample(
181+
variant: BpkInsetBannerVariant,
182+
modifier: Modifier = Modifier,
183+
title: String? = null,
184+
subHeadline: String? = null,
185+
callToAction: BpkInsetBannerCTA? = null,
186+
body: String? = null,
187+
logo: @Composable (() -> Unit)? = null,
188+
) {
189+
Box(modifier = modifier.padding(BpkSpacing.Lg)) {
190+
BpkInsetBanner(
191+
variant = variant,
192+
backgroundColor = when (variant) {
193+
OnDark -> Color(BACKGROUND_ONDARK_COLOR_HEX)
194+
OnLight -> Color(BACKGROUND_ONLIGHT_COLOR_HEX)
195+
},
196+
title = title,
197+
subHeadline = subHeadline,
198+
callToAction = callToAction,
199+
body = body,
200+
logo = logo,
201+
)
202+
}
203+
}
204+
205+
const val BACKGROUND_ONDARK_COLOR_HEX = 0xFFFF6601
206+
const val BACKGROUND_ONLIGHT_COLOR_HEX = 0xFFFFE300

0 commit comments

Comments
 (0)