-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(select/config): module configuration
- Loading branch information
1 parent
bac492e
commit 1037fd3
Showing
10 changed files
with
795 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,23 @@ | ||
<div | ||
class="text-gray-900 cursor-default select-none relative py-2 hover:bg-gray-50" | ||
[ngClass]="{'pl-9 pr-3': selectedIndicatorSide === 'left', 'pl-3 pr-9': selectedIndicatorSide === 'right', 'bg-gray-100': selected === true, 'bg-gray-50': active === true && selected !== true}" | ||
role="option" | ||
> | ||
<div #content> | ||
<ng-content></ng-content> | ||
</div> | ||
<div #content> | ||
<ng-content></ng-content> | ||
</div> | ||
|
||
<span | ||
class="text-primary-600 absolute inset-y-0 items-center pr-4" | ||
[ngClass]="{'left-0': selectedIndicatorSide === 'left', 'right-0': selectedIndicatorSide === 'right', 'flex': selected === true}" | ||
[hidden]="selected === false || !value" | ||
<span | ||
[class]="getIndicatorClasses()" | ||
[hidden]="selected === false || !value || !indicator" | ||
> | ||
<!-- Heroicon name: solid/check --> | ||
<svg | ||
class="h-5 w-5" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20" | ||
fill="currentColor" | ||
aria-hidden="true" | ||
> | ||
<!-- Heroicon name: solid/check --> | ||
<svg | ||
class="h-5 w-5" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20" | ||
fill="currentColor" | ||
aria-hidden="true" | ||
> | ||
<path | ||
fill-rule="evenodd" | ||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" | ||
clip-rule="evenodd" | ||
/> | ||
</svg> | ||
</span> | ||
</div> | ||
<path | ||
fill-rule="evenodd" | ||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" | ||
clip-rule="evenodd" | ||
/> | ||
</svg> | ||
</span> |
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
21 changes: 21 additions & 0 deletions
21
projects/ng-tw/src/modules/select/select-config.interface.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,21 @@ | ||
export interface TwSelectConfig { | ||
select: { | ||
host: { | ||
class: string; | ||
ignore: string; | ||
}; | ||
panel: { | ||
class: string; | ||
mandatoryClass: string; | ||
ignore: string; | ||
}; | ||
}; | ||
option: { | ||
class: string; | ||
ignore: string; | ||
indicatorClass: string; | ||
indicatorMandatoryClass: string; | ||
activeClass: string; | ||
selectedClass: string; | ||
}; | ||
} |
54 changes: 54 additions & 0 deletions
54
projects/ng-tw/src/modules/select/select-config.service.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,54 @@ | ||
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core'; | ||
import { isEmpty, merge } from 'lodash'; | ||
import { TwSelectConfig } from './select-config.interface'; | ||
|
||
/** | ||
* This is not a real service, but it looks like it from the outside. | ||
* It's just an InjectionTToken used to import the config object, provided from the outside | ||
*/ | ||
export const TwSelectSetup = new InjectionToken<TwSelectConfig>('TwSelectConfig'); | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class TwSelectConfigService { | ||
public config: TwSelectConfig = { | ||
select: { | ||
host: { | ||
class: 'bg-white relative border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm', | ||
ignore: '', | ||
}, | ||
panel: { | ||
class: 'bg-white shadow-lg max-h-60 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5', | ||
mandatoryClass: 'absolute z-10 mt-1 w-full overflow-auto focus:outline-none sm:text-sm tw-option-panel-scroll', | ||
ignore: '', | ||
}, | ||
}, | ||
option: { | ||
class: 'block py-2 hover:bg-gray-50 cursor-default select-none relative', | ||
ignore: '', | ||
indicatorClass: 'text-primary-600 pr-4', | ||
indicatorMandatoryClass: 'absolute inset-y-0 items-center', | ||
activeClass: 'font-bold', | ||
selectedClass: 'bg-gray-100', | ||
}, | ||
}; | ||
|
||
constructor(@Optional() @Inject(TwSelectSetup) public options: TwSelectConfig) { | ||
// | ||
// Validate | ||
if (isEmpty(options)) return; | ||
|
||
// | ||
// Merge panel config | ||
if (options.select) { | ||
this.config.select = merge(this.config.select, options.select); | ||
} | ||
|
||
// | ||
// Merge items config | ||
if (options.option) { | ||
this.config.option = merge(this.config.option, options.option); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.