-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(star-rating): new component (#12102)
### Related Ticket(s) [JIRA](https://jsw.ibm.com/browse/ADCMS-6667) ### Description Migrates the`star-rating` component from `carbon-for-aem` into `carbon-for-ibmdotcom`. ### Changelog **New** - adds new `c4d-star-rating` component <!-- React and Web Component deploy previews are enabled by default. --> <!-- To enable additional available deploy previews, apply the following --> <!-- labels for the corresponding package: --> <!-- *** "test: e2e": Codesandbox examples and e2e integration tests --> <!-- *** "package: services": Services --> <!-- *** "package: utilities": Utilities --> <!-- *** "RTL": React / Web Components (RTL) --> <!-- *** "feature flag": React / Web Components (experimental) -->
- Loading branch information
1 parent
27bf4a3
commit dfb0605
Showing
12 changed files
with
403 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,5 @@ body { | |
} | ||
|
||
h3 { | ||
padding-top: $spacing-05; | ||
padding-bottom: $spacing-07; | ||
padding-block: $spacing-05 $spacing-07; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/web-components/src/components/star-rating/__stories__/README.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Meta, Props, Story, Canvas, Description } from '@storybook/addon-docs'; | ||
import { cdnJs } from '../../../globals/internal/storybook-cdn'; | ||
import '../index'; | ||
|
||
<Meta title="Star Rating" /> | ||
|
||
# Star Rating | ||
|
||
<Canvas withToolbar> | ||
<Story id="components-star-rating--default" height="100px" /> | ||
</Canvas> | ||
|
||
<Description markdown={`${cdnJs({ components: ['star-rating'] })}`} /> | ||
|
||
## `<c4d-star-rating>` attributes, properties, and events | ||
|
||
<Props of="c4d-star-rating" /> |
72 changes: 72 additions & 0 deletions
72
packages/web-components/src/components/star-rating/__stories__/star-rating.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright IBM Corp. 2020, 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { html } from 'lit'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import '../index'; | ||
import readme from './README.stories.mdx'; | ||
import { grid8ColCentered } from '../../../globals/internal/storybook-decorators'; | ||
import { boolean, number, text } from '@storybook/addon-knobs'; | ||
|
||
export const Default = (args) => { | ||
const { disableTooltip, label, labelHref, rating, starCount, tooltipText } = | ||
args?.StarRating ?? {}; | ||
return html` | ||
<c4d-star-rating | ||
?disableTooltip="${disableTooltip}" | ||
label="${ifDefined(label || undefined)}" | ||
label-href="${ifDefined(labelHref || undefined)}" | ||
rating="${rating}" | ||
star-count="${starCount}" | ||
tooltip="${tooltipText}"></c4d-star-rating> | ||
`; | ||
}; | ||
|
||
export const NoLabel = (args) => { | ||
const { disableTooltip, rating, starCount, tooltipText } = (args = | ||
args?.StarRating ?? {}); | ||
|
||
return html` | ||
<c4d-star-rating | ||
?disableTooltip="${disableTooltip}" | ||
rating="${rating}" | ||
star-count="${starCount}" | ||
tooltip="${tooltipText}"></c4d-star-rating> | ||
`; | ||
}; | ||
|
||
export default { | ||
title: 'Components/Star Rating', | ||
parameters: { | ||
...readme.parameters, | ||
hasStoryPadding: true, | ||
knobs: { | ||
StarRating: () => { | ||
const rating = number('Star Rating', 4.5); | ||
const label = text('Label text (optional)', '42 G2 reviews'); | ||
const labelHref = text('Label link (optional)', ''); | ||
const starCount = number('Max number of stars (optional)', 5); | ||
const tooltipText = text('Tooltip text (optional)', ''); | ||
const disableTooltip = boolean('Disable tooltip (optional)', false); | ||
return { | ||
rating, | ||
label, | ||
labelHref, | ||
starCount, | ||
tooltipText, | ||
disableTooltip, | ||
}; | ||
}, | ||
}, | ||
}, | ||
decorators: [ | ||
(story) => grid8ColCentered(story), | ||
(story) => html` <div style="margin-block-start: 2rem;">${story()}</div> `, | ||
], | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/web-components/src/components/star-rating/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright IBM Corp. 2020, 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import './star-rating'; |
76 changes: 76 additions & 0 deletions
76
packages/web-components/src/components/star-rating/star-rating.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// Copyright IBM Corp. 2024 | ||
// | ||
// This source code is licensed under the Apache-2.0 license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
|
||
@use '@carbon/styles/scss/config' as *; | ||
@use '@carbon/styles/scss/spacing' as *; | ||
@use '@carbon/styles/scss/type' as *; | ||
@use '@carbon/styles/scss/themes' as *; | ||
@use '@carbon/styles/scss/theme' as *; | ||
@use '@carbon/styles/scss/utilities/tooltip' as *; | ||
@use '@carbon/styles/scss/components/button/tokens' as *; | ||
@use '@carbon/ibmdotcom-styles/scss/globals/vars' as *; | ||
|
||
:host(#{$c4d-prefix}-star-rating) { | ||
display: inline-block; | ||
|
||
.#{$prefix}-star-rating { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: $spacing-03 $spacing-05; | ||
} | ||
|
||
.#{$prefix}-star-rating__stars { | ||
display: inline-flex; | ||
align-items: center; | ||
margin: 0; | ||
|
||
&:not([disableTooltip]) { | ||
@include tooltip--trigger('definition', top); | ||
@include tooltip--placement('definition', 'top', 'center'); | ||
} | ||
} | ||
|
||
.#{$prefix}-star-count__star { | ||
svg { | ||
display: block; | ||
fill: $button-primary; | ||
} | ||
} | ||
|
||
.#{$prefix}-star-count__star--half { | ||
position: relative; | ||
|
||
svg { | ||
position: absolute; | ||
inset: 0; | ||
} | ||
|
||
svg:nth-of-type(1) { | ||
position: initial; | ||
} | ||
|
||
svg:nth-of-type(2):dir(rtl) { | ||
transform: scaleX(-1); | ||
} | ||
} | ||
|
||
.#{$prefix}-star-rating__label, | ||
.#{$prefix}-star-rating__label a { | ||
@include type-style('body-compact-02'); | ||
|
||
color: $border-inverse; | ||
} | ||
|
||
.#{$prefix}-star-rating__label a { | ||
text-decoration: none; | ||
|
||
&:hover, | ||
&:focus { | ||
text-decoration: underline; | ||
} | ||
} | ||
} |
Oops, something went wrong.