Skip to content

Commit

Permalink
fix(select): add background to selected item and remove color's prop (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipefialho authored Sep 9, 2024
1 parent 52f2161 commit 226aa78
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 83 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export namespace Components {
"trigger"?: string;
}
interface AtomSelect {
"color"?: 'primary' | 'secondary' | 'danger';
"disabled"?: boolean;
"errorText"?: string;
"fill": 'solid' | 'outline';
Expand Down Expand Up @@ -709,7 +708,6 @@ declare namespace LocalJSX {
"trigger"?: string;
}
interface AtomSelect {
"color"?: 'primary' | 'secondary' | 'danger';
"disabled"?: boolean;
"errorText"?: string;
"fill"?: 'solid' | 'outline';
Expand Down
18 changes: 1 addition & 17 deletions packages/core/src/components/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@
--ion-color-step-550: --color-neutral-light-1;
min-height: var(--atom-select-min-height);

&[color='primary'] {
--highlight-color-focused: var(--color-brand-primary-regular);
--atom-icon-color: var(--color-brand-primary-regular);
}

&[color='secondary'] {
--highlight-color-focused: var(--color-brand-secondary-regular);
}

&[color='danger'] {
--highlight-color-focused: var(--color-contextual-error-regular);
}

&.has-error {
--border-color: var(--color-contextual-error-regular);
--placeholder-color: var(--text-color);
Expand Down Expand Up @@ -82,15 +73,8 @@
z-index: var(--zindex-100);

.select-expanded + & {
&.atom-color--primary {
--atom-icon-color: var(--color-brand-primary-regular);
}

&.atom-color--secondary {
--atom-icon-color: var(--color-brand-secondary-regular);
}
--atom-icon-color: var(--color-brand-secondary-regular);

&.atom-color--danger,
&.has-error {
--atom-icon-color: var(--color-contextual-error-regular);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('AtomSelect', () => {
name="test"
label="Select a fruit"
placeholder="Select an option"
color="primary"
mode="ios"
fill="outline"
disabled
Expand All @@ -104,9 +103,9 @@ describe('AtomSelect', () => {
await page.waitForChanges()

expect(page.root).toEqualHtml(`
<atom-select color="primary" disabled="" fill="outline" label="Select a fruit" mode="ios" multiple="" name="test" placeholder="Select an option">
<atom-select disabled="" fill="outline" label="Select a fruit" mode="ios" multiple="" name="test" placeholder="Select an option">
<mock:shadow-root>
<ion-select class="atom-select" color="primary" disabled="" fill="outline" interface="popover" label="Select a fruit" label-placement="stacked" mode="ios" multiple="" name="test" placeholder="Select an option" shape="round">
<ion-select class="atom-select" color="secondary" disabled="" fill="outline" interface="popover" label="Select a fruit" label-placement="stacked" mode="ios" multiple="" name="test" placeholder="Select an option" shape="round">
<ion-select-option value="apple">apple</ion-select-option>
<ion-select-option value="banana" disabled>banana</ion-select-option>
<ion-select-option value="orange">orange</ion-select-option>
Expand Down Expand Up @@ -135,7 +134,7 @@ describe('AtomSelect', () => {
<ion-select-option disabled="" value="banana">banana</ion-select-option>
<ion-select-option value="orange">orange</ion-select-option>
</ion-select>
<atom-icon class="atom-color--secondary atom-icon" icon="account-multiple"></atom-icon>
<atom-icon class="atom-icon" icon="account-multiple"></atom-icon>
</mock:shadow-root>
</atom-select>
`)
Expand Down
13 changes: 3 additions & 10 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { IconProps } from '../../icons'
export class AtomSelect {
@Element() selectEl!: HTMLIonSelectElement

@Prop() color?: 'primary' | 'secondary' | 'danger' = 'secondary'
@Prop() disabled?: boolean
@Prop() errorText?: string
@Prop() fill: 'solid' | 'outline' = 'solid'
Expand Down Expand Up @@ -104,7 +103,7 @@ export class AtomSelect {
placeholder={this.placeholder}
disabled={this.disabled}
multiple={this.multiple}
color={this.color}
color='secondary'
mode={this.mode}
value={this.value}
tabindex={this.readonly && '-1'}
Expand All @@ -114,7 +113,7 @@ export class AtomSelect {
onIonFocus={this.handleFocus}
onIonCancel={this.handleCancel}
interfaceOptions={{
cssClass: `atom-select-color-${this.color}`,
cssClass: `atom-select__popover`,
}}
>
{this.options.map((option) => (
Expand All @@ -136,13 +135,7 @@ export class AtomSelect {
</div>
)}
{this.icon && (
<atom-icon
class={{
[`atom-icon`]: true,
[`atom-color--${this.color}`]: true,
}}
icon={this.icon}
></atom-icon>
<atom-icon class='atom-icon' icon={this.icon}></atom-icon>
)}
</Host>
)
Expand Down
10 changes: 0 additions & 10 deletions packages/core/src/components/select/stories/select.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ export const SelectStoryArgs = {
category: Category.PROPERTIES,
},
},
color: {
control: 'select',
options: ['primary', 'secondary', 'danger'],
defaultValue: { summary: 'secondary' },
description: "The color to use from your application's color palette.",
table: {
category: Category.PROPERTIES,
},
},
multiple: {
control: 'boolean',
defaultValue: { summary: false },
Expand Down Expand Up @@ -160,7 +151,6 @@ export const SelectStoryArgs = {
}

export const SelectComponentArgs = {
color: 'secondary',
disabled: false,
readonly: false,
multiple: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const createSelect = (args) => {
return html`
<atom-select
placeholder=${args.placeholder}
color=${args.color}
fill=${args.fill}
disabled=${args.disabled}
readonly=${args.readonly}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default {
const createSelect = (args) => (
<AtomSelect
placeholder={args.placeholder}
color={args.color}
fill={args.fill}
disabled={args.disabled}
readonly={args.readonly}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const createSelect = (args) => ({
template: `
<AtomSelect
placeholder="${args.placeholder}"
color="${args.color}"
fill="${args.fill}"
disabled="${args.disabled}"
readonly="${args.readonly}"
Expand Down
57 changes: 20 additions & 37 deletions packages/core/src/global/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,52 +77,35 @@ Issue: https://github.com/ionic-team/ionic-framework/issues/27500
*/

.select-popover {
.item-checkbox-checked {
--color: var(--ion-color-medium-shade);
}

ion-checkbox {
--checkbox-background-checked: var(--ion-color-medium-shade);
--border-color-checked: var(--ion-color-medium-shade);
}

.item-radio-checked {
--background: rgba(var(--ion-color-medium-rgb));
--background-focused: var(--ion-color-medium);
--background-hover: var(--ion-color-medium);
}

&.atom-select-color-primary {
.item-checkbox-checked {
--color: var(--ion-color-primary);
}

ion-checkbox {
--checkbox-background-checked: var(--ion-color-primary);
--border-color-checked: var(--ion-color-primary);
&.atom-select__popover {
.select-interface-option {
--background-hover: var(--color-neutral-light-5);
--background-hover-opacity: 0.6;
}

.item-radio-checked {
--background: rgba(var(--ion-color-primary-rgb));
--background-focused: var(--ion-color-primary);
--background-hover: var(--ion-color-primary);
--background: rgba(var(--color-brand-secondary-light-2-rgb));
--background-focused: var(--color-brand-secondary-regular);
--background-hover: var(--color-brand-secondary-regular);
--background-hover-opacity: 0.1;
--color-hover: var(--color-brand-secondary-regular);
--color: var(--color-brand-secondary-regular);
}
}

&.atom-select-color-secondary {
.item-checkbox-checked {
--color: var(--ion-color-secondary);
--background-hover: var(--color-brand-secondary-regular);
--background-hover-opacity: 0.1;
--color: var(--color-brand-secondary-regular);
--color-hover: var(--color-brand-secondary-regular);

&::part(native) {
--background: rgba(var(--color-brand-secondary-light-2-rgb));
}
}

ion-checkbox {
--checkbox-background-checked: var(--ion-color-secondary);
--border-color-checked: var(--ion-color-secondary);
}

.item-radio-checked {
--background: rgba(var(--ion-color-secondary-rgb));
--background-focused: var(--ion-color-secondary);
--background-hover: var(--ion-color-secondary);
--checkbox-background-checked: var(--color-brand-secondary-regular);
--border-color-checked: var(--color-brand-secondary-regular);
}
}
}

0 comments on commit 226aa78

Please sign in to comment.